I have a hug table with 170,000 records.

我有一张170,000条记录的拥抱表。

What is difference between this query

这个查询有什么区别

Showing rows 0 - 299 (1,422 total, Query took 1.9008 sec)
    SELECT 1 FROM `p_apartmentbuy` p 
    where 
    p.price between 500000000 and 900000000
    and p.yard = 1
    and p.dateadd between 1290000000 and 1320000000
    ORDER BY `p`.`id` desc
    limit 1669

Explain

And this one:

和这个:

Showing rows 0 - 299 (1,422 total, Query took 0.2625 sec)
    SELECT 1 FROM `p_apartmentbuy` p 
    where 
    p.price between 500000000 and 900000000
    and p.yard = 1
    and p.dateadd between 1290000000 and 1320000000
    ORDER BY `p`.`id` desc
    limit 1670

Explain:

Both of these queries are using 1 table with same data and have same where clasue, but only limit row count are different

这两个查询都使用1个具有相同数据的表,并且具有相同的clasue,但只有限制行数不同

2 个解决方案

#1


2

MySQL has a buffer for sorting. When the stuff to be sorted is too big, it sorts chunks, then mergesorts them. This is called "filesort". Your 1670-th row apparently just overflows the sort buffer.

MySQL有一个用于排序的缓冲区。当要排序的东西太大时,它会对块进行排序,然后合并它们。这称为“filesort”。你的第1670行显然只是溢出了排序缓冲区。

Read more details here.

在这里阅读更多细节。

Now why it picks another key for the in-memory sort... I am not too sure; but apparently its strategy is not quite good since it ends up being slower.

现在为什么它选择内存排序的另一个键...我不太确定;但显然它的策略并不是很好,因为它最终会变慢。

更多相关文章

  1. 基于缓冲区数据创建文件
  2. Android中bindService的细节之二:从进程的角度分析绑定Service的
  3. Java nio 学习笔记(一) Buffer(缓冲区)与Channel(通道)的相关知识
  4. Java IO流系列(四)—— 从字节流及其缓冲区到转换流
  5. Java的Grizzly为缓冲区占用了大量内存?

随机推荐

  1. 在jQuery Mobile中做$(document).ready的正
  2. jQuery使用微调器加载整个HTML页面
  3. 通过调用返回参数的本地函数来构建Ajax D
  4. Zepto自定义选择器与Jq存在差异
  5. EasyUI动态展示用户信息
  6. js 中输入验证
  7. jquery兼容性问题
  8. JQuery和Struts实现Ajax文件上传
  9. 用JQuery写的一个简单的验证码功能
  10. 使用jQuery确认对话框防止上的表单回发