0

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?

3
  • Do you have an index on column id ? Commented May 28, 2013 at 18:11
  • Yes but the issue is the resultant query is very large in length, reading that parameter form file would be great if possible Commented May 28, 2013 at 18:31
  • The query size should not matter so much, this is why I asked. I will post an answer in a minute. Commented May 28, 2013 at 18:32

1 Answer 1

5

Yes, you can (TM)!

  • First step: Use CREATE TEMPORARY TABLE temp (id ... PRIMARY KEY) and LOAD DATA INFILE ... to create and fill a temporary table holding your value list
  • Second step: Run 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.