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.
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?
Yes, you can (TM)!
CREATE TEMPORARY TABLE temp (id ... PRIMARY KEY)
and LOAD DATA INFILE ...
to create and fill a temporary table holding your value listSELECT 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.