I have 3 tables.
They have
table_a 5m records
table_b 20m records
table_c 20m records
I'm performing the query below.
SELECT * FROM table_a a
INNER JOIN table_b b ON a.a_id = b.a_id AND b.b_come='100'
INNER JOIN table_c c ON b.c_id = c.c_id AND c.c_type IN ('A','B')
WHERE date(a.a_dt) = '01/01/2012 00:00:00.000'
The query is quite slow. I think it is because the data in its nature they have
about 1000 records of a.a_id = b.a_id
and
about 20m*20m records of b.c_id = c.c_id.
I think I should get the result of a.a_id = b.a_id then do the one of b.c_id = c.c_id so that the performance could be a lot better. But it seems INNER JOIN has no concept of order. How should I do this to improve the performance?
a_dt
column. The chances are that there are better ways to write that condition, but which is best depends on the type ofa_dt
. Which version of Informix and which platform you're running on might be relevant. It is always relevant to ask 'have you run UPDATE STATISTICS (or, depending on the version, has the system done it for you)?'