大表下的 MySQL 性能

发布于 2024-11-14 21:45:43 字数 611 浏览 0 评论 0原文

我有一个简历表 - 姓名、简历文本、邮政编码、名字、姓氏、经度、纬度、邮政编码... 500,000+行

我也查询它的方式:

按位置,例如:

1) SELECT * FROM resumes 
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213) 
AND (longitude BETWEEN -110.873064254 AND -108.993603746)) 
GROUP BY lastname,longitude 
LIMIT 0, 50 
by name

2) SELECT * from resumes 
   (MATCH(resume) AGAINST ('donald')) AS relevance 
    FROM resumes 
    WHERE (MATCH(resume) AGAINST ('donald')) 
    GROUP BY lastname,longitude 
    ORDER BY relevance DESC 
    LIMIT 0, 50

对该表的查询一开始非常慢,但之后相同的查询速度更快,我认为它正在缓存它......

我怎样才能加快这些查询的速度?谢谢

i have a table of resumes - names, resume text, zipcode, firstname, lastname, longitude, latitude, zip ... 500,000+ rows

i query it too ways:

by location, example:

1) SELECT * FROM resumes 
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213) 
AND (longitude BETWEEN -110.873064254 AND -108.993603746)) 
GROUP BY lastname,longitude 
LIMIT 0, 50 
by name

2) SELECT * from resumes 
   (MATCH(resume) AGAINST ('donald')) AS relevance 
    FROM resumes 
    WHERE (MATCH(resume) AGAINST ('donald')) 
    GROUP BY lastname,longitude 
    ORDER BY relevance DESC 
    LIMIT 0, 50

queries on this table are very slow at first, but same query afterwards is faster, i think it's caching it ...

how can i speed up these queries? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

也只是曾经 2024-11-21 21:45:43
1) SELECT * FROM resumes 
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213) 
AND (longitude BETWEEN -110.873064254 AND -108.993603746)) 
GROUP BY lastname,longitude 
LIMIT 0, 50 
by name

这个可以很少使用 btree 索引。最好的情况是,它会抓取所有适合纬度或经度的位置,并调查沿其他维度的潜在行。您想要的是它只调查适合较小盒子的行。

为此,您需要一个空间索引

2) SELECT * from resumes 
   (MATCH(resume) AGAINST ('donald')) AS relevance 
    FROM resumes 
    WHERE (MATCH(resume) AGAINST ('donald')) 
    GROUP BY lastname,longitude 
    ORDER BY relevance DESC 
    LIMIT 0, 50

同样,这也需要一种不是 btree 的特殊索引 -- a

1) SELECT * FROM resumes 
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213) 
AND (longitude BETWEEN -110.873064254 AND -108.993603746)) 
GROUP BY lastname,longitude 
LIMIT 0, 50 
by name

This one can make little use of btree indexes. At best, it would grab all locations that fit for the latitude, or the longitude, and investigate potential rows along the other dimension. What you want is for it to only investigate rows that fit in a smaller box.

For this, you need a spacial index.

2) SELECT * from resumes 
   (MATCH(resume) AGAINST ('donald')) AS relevance 
    FROM resumes 
    WHERE (MATCH(resume) AGAINST ('donald')) 
    GROUP BY lastname,longitude 
    ORDER BY relevance DESC 
    LIMIT 0, 50

Likewise, this also needs a special kind of index which is not btree -- a full text index to be specific.

很糊涂小朋友 2024-11-21 21:45:43
  1. 对用于连接表的所有字段使用索引。
  2. 对您在 where 子句中使用的字段使用索引。
  3. 不要使用“选择 *”,仅选择您需要的字段
  4. 分组依据对分组字段上的结果集进行排序,如果您对不同的字段(或不同的顺序)进行排序,您将强制进行额外的排序,从而减慢速度。
  5. MySQL 执行快捷方式评估,将限制最大行数的条件放在 where 子句中。

  6. 如果您布局表格时没有重复行,那么使用分组依据选择 * 是一种不同的“消除重复行”编写方式,您也不需要分组依据。这将大大加快你的查询速度。

  7. 指定您的纬度和经度字段作为类型点,并在其上放置空间索引。我会给你一个链接,但我现在用的是 iPhone,所以现在有点麻烦。
  1. Use indexes on all fields used to join tables.
  2. Use indexes on the fields that you use in your where clause.
  3. Don't use 'select *' select only the fields that you need.
  4. Group by sorts your resultset on the grouped fields, if you an order by on a different field (or a different order) you are forcing an extra sort slowing things down.
  5. MySQL does shortcut evaluation put the condition that limits the maximum number of rows first in your where clause.

  6. Select * with a group by is a different way of writing "eliminate duplicate rows" if you lay out your tables so there are no duplicate rows to begin with you don't need the group by either. This will speed up your queries a lot.

  7. Specify your lat and longitude field as type point and put a spatial index on those. I'd give you a link but I'm on the iphone now so that's a bit of a hassle now.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文