Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 按查询复制到tmp表的订单_Mysql_Sql - Fatal编程技术网

Mysql 按查询复制到tmp表的订单

Mysql 按查询复制到tmp表的订单,mysql,sql,Mysql,Sql,我的MYSQL查询: select id, title, slug, price, image, cat from demo where main_cat = 1 order by id desc limit 200000, 20 详细说明: select_type : SIMPLE table : demo type :ref possible_keys :main_cat key :main_cat key_len:4 ref :const rows :90509

我的MYSQL查询:

select id, title, slug, price, image, cat
  from demo
 where main_cat = 1
 order by id desc
 limit 200000, 20
详细说明:

select_type : SIMPLE
table : demo 
type :ref 
possible_keys :main_cat 
key :main_cat  
key_len:4  
ref :const 
rows :9050910 
Extra :Using where; Using filesort
MySQL说:


我的查询只包含ORDER BY,为什么转到TMP表?

您可以找到标准错误代码的含义:

$ perror 28
OS error code  28:  No space left on device
因此,在/tmp所在的文件系统上没有足够的空间。它可能在一段时间内写得很好,但试图写一个太大的结果集

解释输出不显示临时表。但它确实显示了“使用文件排序”,如果结果集足够大,它也可以使用磁盘空间

例如,如果必须对200000行进行排序才能找到偏移量::-)

您的
image
列是否是BLOB中的实际图像?这可以解释结果集的大小

对偏移量使用具有非常大数字的LIMIT不是一个好主意。MySQL必须先生成整个结果集,然后才能进行偏移

最好按值进行偏移,而不是按位置进行偏移

选择id、title、slug、price、image、cat
从演示
其中main_cat=1且id<$lower_id_from_previous_页面
按id描述订购
限制20

我们不知道您的表结构,我们甚至没有完整的查询和解释结果,所以您希望我们如何帮助您?您可以编辑您的问题,以包括
解释的输出吗?@peter explain现在添加的输出您可以使用奇妙的perror命令,但基本上您已经用完了空间:)嗯,磁盘空间不仅仅用于诱惑,例如,它还将用于索引搜索。如果你想处理12gb的数据,你需要清理磁盘上的空间,仅此而已。VARCHAR中除id和price列之外的所有列…以及id<$lower\u id\u from\u previous\u page,这在我的情况下是不可能的,因为我在许多地方也使用了ORDER BY'bestseller',然后将
tmpdir
配置为一个具有更多空间的文件系统。
$ perror 28
OS error code  28:  No space left on device
select id, title, slug, price, image, cat
  from demo
 where main_cat = 1 and id < $lowest_id_from_previous_page
 order by id desc
 limit 20