[英]MySQL read parameter from file for select statement
I have a select query as follows:我有一个选择查询如下:
select * from abc where id IN ($list);
The problem with the length of variable $list
, it may have a length of 4000-5000 characters, as a result of which the length of actually executed query increases and its get pretty slow.变量
$list
的长度问题,它可能有 4000-5000 个字符的长度,因此实际执行的查询长度增加并且变得非常慢。
Is there a method to store the values of $list
in a file and ask MySQL to read it from that file, similar to LOAD DATA INFILE 'file_name'
for insertion into table?是否有一种方法可以将
$list
的值存储在文件中并要求 MySQL 从该文件中读取它,类似于LOAD DATA INFILE 'file_name'
插入表中?
Yes, you can (TM)!是的,你可以(TM)!
CREATE TEMPORARY TABLE temp (id ... PRIMARY KEY)
and LOAD DATA INFILE ...
to create and fill a temporary table holding your value listCREATE TEMPORARY TABLE temp (id ... PRIMARY KEY)
和LOAD DATA INFILE ...
来创建并填充一个临时表来保存您的值列表SELECT abc.id FROM abc INNER JOIN temp ON abc.id=temp.id
SELECT abc.id FROM abc INNER JOIN temp ON abc.id=temp.id
I have the strong impression this only checks out as a win, if you use the same value list quite a few times.我有强烈的印象,如果您多次使用相同的值列表,这只会被视为胜利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.