Subject Re: Max length of SQL statement
Author Tom Conlon
Hi Stephen,


> > The IN limit is reached before the maximum SQL size limit.
> > It's about 1500 items or so.
>
> In that case, maybe someone can show me a better way to do what I am
> trying to do.

I came up against this problem with a general-purpose user query
module that could not predict the questions that were going to be
asked. For certain columns that would generate a sizeable IN() clause
it now populates the following table:

CREATE TABLE QRYCRITERIA
(
USERID INTEGER DEFAULT 0 NOT NULL ,
CRITERIACOLUMN VARCHAR(50) DEFAULT '' NOT NULL,
CRITERIAVALUE VARCHAR(255),
ISMANDATORY INTEGER DEFAULT 0
);

And leads to queries of the form:

SELECT c.contid, c.surname, c.forename, c.dob, c.postcode, c.filed,
c.available, c.email
FROM cont c
JOIN QryCriteria q1 on (q1.userid=8 and
q1.CRITERIACOLUMN='AREAID' and c.AREAID = q1.criteriavalue)
------------------------------------------------

The actual request was
AREAID =
IN(2321,12,17,22,30,32,36,39,54,58,60,72,78,94,96,115,120,140,150,188,189,194,199,208,227,255,275,277,296,307,317,318,319,325,326,328,351,371,383,397,428,430,478,480,483,485,496,499,512,513,514,517,525,530,553,555,564,579,581,587,601,608,612,621,633,636,645,649,661,668,673,708,709,727,737,739,778,798,803,806,860,881,883,894,898,913,914,922,933,969,977,1012,1014,1032,1061,1062,1064,1066,1102,1110,1117,1131,1132,1144,1158,1169,1196,1201,1222,1234,1235,1261,1266,1272,1299,1301,1311,1313,1314,1326,1335,1336,1337,1344,1368,1374,1386,1389,1395,1402,1404,1415,1416,1427,1430,1432,1436,1445,1448,1468,1470,1471,1481,1482,1483,1488,1492)

FB 1.5 always seems happiest using JOINS. IN() clauses can engage
multiple copies of indexes (if they are available) and this, in my
experience, leads to a performance hit.

HTH,
Tom