Tuesday 4 September 2018

mysql large query does not respond

we have table with around 9 hundred thousand records. we are trying to execute a query with having large data (NOTE: the query is large )

like <some query> and agt.item in (',productRange,.......<very large data, having around 2 lakh chars>)

with this the query is failing saying syntax error. but with less number of items in query it executes. Please let me know how to handle this kind of issues.

Most DBMS works terrible with large parameter lists. So if you have a large "IN" list, e.g.
SELECT *
FROM   foo
WHERE  bar IN ('1','2','3','4'...,'500000')

you will get very poor performance compared with having a table containing all values you want to select on, and joining the two tables:
CREATE TABLE baz (
    bar VARCHAR
)

INSERT INTO baz(bar) VALUES ('1');
INSERT INTO baz(bar) VALUES ('2');
INSERT INTO baz(bar) VALUES ('3');
INSERT INTO baz(bar) VALUES ('4');
...
INSERT INTO baz(bar) VALUES ('500000');

SELECT *
FROM   foo,
       baz
WHERE  foo.bar = baz.bar

So, as MySQL does not have table valued parameters your best bet is to store the data in a temp table instead of typing it out in the query, and don't forget you will need an index on the value you are filtering on (agt.item in your case).

0 comments:

Post a Comment