TZQuery's Open too slow
Posted: 24.08.2005, 15:23
Hi there,
I've an interesting question. I'm using Delphi7 with ZeosLib 6.5.1, and want to run a query form a MySQL 4.1 dabatase. I have the following query:
SELECT A.Field1, A.Field2, A.Field3, MAX(B.Field4) AS NewName
FROM Table1 A, Table2 B
WHERE BINARY UPPER(SUBSTRING(A.Field1,1,3)) = '123'
AND A.Fieldx = B.Fieldx
GROUP BY A.Field1
Table1 and Table2 are indexed for all necessary fields. (But it's not important for my problem.)
When I run this query from MySQL Control Center, I get some (31) rows and the query time is 0,04 sec. It's great.
But when I run the query from Delphi using the TZQuery component's Open method, the running time is about 1 second. I've no idea why and how I could decrease the query time. I've tried for other queries as well, but the shorter string I give in the query, the slower the query runs...
E.g.: if in the mentioned query I change:
(SUBSTRING(A.Field1,1,2)) = '12', the query time:
MySqlCC: 0,06 sec (401 rows), Delphi: about 2,5 seconds.
If I change again:
(SUBSTRING(A.Field1,1,1)) = '1', the query time:
MySqlCC: 0,35 sec (4965 rows!), Delphi: about 8 seconds!
Remember: the queries are exactly the same and it takes too long until the Open menthod executes. Any idea? Thanks.
I've an interesting question. I'm using Delphi7 with ZeosLib 6.5.1, and want to run a query form a MySQL 4.1 dabatase. I have the following query:
SELECT A.Field1, A.Field2, A.Field3, MAX(B.Field4) AS NewName
FROM Table1 A, Table2 B
WHERE BINARY UPPER(SUBSTRING(A.Field1,1,3)) = '123'
AND A.Fieldx = B.Fieldx
GROUP BY A.Field1
Table1 and Table2 are indexed for all necessary fields. (But it's not important for my problem.)
When I run this query from MySQL Control Center, I get some (31) rows and the query time is 0,04 sec. It's great.
But when I run the query from Delphi using the TZQuery component's Open method, the running time is about 1 second. I've no idea why and how I could decrease the query time. I've tried for other queries as well, but the shorter string I give in the query, the slower the query runs...
E.g.: if in the mentioned query I change:
(SUBSTRING(A.Field1,1,2)) = '12', the query time:
MySqlCC: 0,06 sec (401 rows), Delphi: about 2,5 seconds.
If I change again:
(SUBSTRING(A.Field1,1,1)) = '1', the query time:
MySqlCC: 0,35 sec (4965 rows!), Delphi: about 8 seconds!
Remember: the queries are exactly the same and it takes too long until the Open menthod executes. Any idea? Thanks.