Page 1 of 2

speed of select

Posted: 09.01.2006, 15:37
by killerjohn
I've the following piece of code (MySQL 5.0.15 and Delphi 2006). The result is about 90.000 records. #1 execution time is about 2 seconds. #2 execution time is about 15 minutes. Why??? :cry:

//#1
list.sql.text := 'SELECT * FROM POSITION_001 ORDER BY D_SECONDS;';
list.open;

//#2
while not list.eof do
begin
list.next;
end;


(Sorry for my english) :oops:

Posted: 10.01.2006, 16:00
by mdaems
Hi,

That's because the first statement is just preparing the database server to return the results and the second statement is retrieving these results one by one over the network connection. For each record caches will be filled and the current record of the dataset changes. It still processes 100 records per second this way.
How big are your records? Do you need all the fields? Do you need all those records? I can't imagine somebody wants to see 90000 records at once. (Or are you exporting these data to file?) If you are making statistics you should try to write some sql doing the work.

Mark

Posted: 11.01.2006, 16:11
by dragos
Try setting TZQuery's RequestLive option to TRUE (I assume you're using a TZQuery).

If it works (i.e. it takes less than 15'), I'll then tell you why :-)

Posted: 11.01.2006, 18:30
by killerjohn
Hi!

I need all 90.000 records, and all columns. This is a table with GPS navigation coordinates , and I use very complex calculations with Delphi. :(

Posted: 12.01.2006, 12:07
by dragos
I understand, but does the RequestLive option make a difference?

Posted: 12.01.2006, 22:24
by killerjohn
I'm using TZReadOnlyQuery.... I think it's faster because it's "read only". or not ? :oops:

Posted: 13.01.2006, 09:11
by dragos
killerjohn wrote:I'm using TZReadOnlyQuery.... I think it's faster because it's "read only". or not ? :oops:
If you're using large SELECTs, TZQuery w/ RequestLive will be faster (my experience some time ago - maybe now it is different).
And the explanation had something to do with the way qry.Next() and the mysql driver work.
I remember having this problem some time ago, and after some profiling found the culprit and then the solution.

Hope it still works.

Posted: 18.01.2006, 09:24
by killerjohn
I've checked TZQuery, but there is no RequestLive property. Only hidden in the source code :) :?:

Posted: 18.01.2006, 12:27
by gto
What is your Zeos build? In the last one (cvs 13/10/2005), requestlive become readonly ;)

Also, the options are inverted, when requestlive was active, now means readonly will be inactive :)

Posted: 31.03.2006, 12:22
by killerjohn
Hello!

1st : sorry for my bad English...

Please give me some hint about this problem:

:cry:





Tables:

create table DEF_OBJECT
(
ID INTEGER not null,
OBJECT_TYPE_ID INTEGER not null,
LAST_DETAIL_ID INTEGER not null,
INACTIVE TINYINT UNSIGNED not null default 0,
INTEGRATED TINYINT UNSIGNED not null default 0,
USER_KEY VARCHAR(255),
primary key (ID)
);

create table DETAIL_OBJECT
(
ID INTEGER not null,
OBJECT_ID INTEGER not null,
PREV_DETAIL_ID INTEGER not null,
D_DATE DATE not null,
D_TIME TIME not null,
D_DATETIME DATETIME not null,
DESCRIPTION TEXT,
primary key (ID)
);

create table DEF_OBJECT_PROPERTY
(
ID INTEGER not null,
DETAIL_ID INTEGER not null,
PROPERTY_ID INTEGER not null,
VALUE_INT INTEGER,
VALUE_STR TEXT,
VALUE_DATE DATETIME,
VALUE_EXT DOUBLE,
primary key (ID)
);

Query:

SELECT *,op.ID as OPID,h.ID as OBJID FROM DEF_OBJECT h INNER JOIN DETAIL_OBJECT d ON h.LAST_DETAIL_ID=d.ID INNER JOIN DEF_OBJECT_PROPERTY op ON op.DETAIL_ID=d.ID WHERE h.OBJECT_TYPE_ID=:pObjectTypeID ORDER BY h.ID,op.ID;

Record count in database:
DEF_OBJECT : 1100
DETAIL_OBJECT : 1100
DEF_OBJECT_PROPERTY : 15400

The Delphi Code:

sql.Open;
While not sql.Eof Do
Begin
o := CDBO_Object.Create;
o.iOuterPropertyCache := True;
o.iPropertyCache := iPropertyCache;
o.LoadHeaderFromSQL(sql);
o.LoadObjectPropertiesFromSQL(sql);
iObjects.Add(o);
End;
sql.Free;

Run times:
mysql console : very fast
delphi code : >10 seconds!!! (my .exe's CPU=88%, and mysql's CPU=10%)

Posted: 31.03.2006, 12:26
by killerjohn
When I change the Delphi code to this :

sql.Open;
While not sql.Eof Do
Begin
sql.Next;
End;
sql.Free;

my program is not faster - Zeos is toooooo slow.... :(

Posted: 31.03.2006, 12:49
by mdaems
Did you run this code 'dry'? I mean, without the code between the begin and end clauses? Just to make sure it's only the zeos component that is slow. I don't know what these 'Load...' functions do, but they can also be slow.

If the loop keeps taking that long we'll have to take a deeper look at it. Is the data in your table confidential? If not, please send me a private message to agree how we can exchange your files. (Data and test project)

Mark


BTW : I hope you did not forget to fetch next record (never ending loop, of course)? If it's in one of these 'Load...' functions, i would not recommend to write it there. Even if it works, you will later spend hours to find where it exactly is.

Posted: 31.03.2006, 12:51
by mdaems
Oops,

We 've been writing together.

Posted: 31.03.2006, 12:55
by killerjohn
it's simple... this code on 15400 records (all columns and rows needed) :

<----------------- 0 second
sql.Open;
<----------------- 1 second
While not sql.Eof Do
Begin
sql.Next;
End;
sql.Free;
<----------------- 10 second

Posted: 31.03.2006, 13:16
by killerjohn
Have somebody some experience with the MyDAC component pack ? (http://crlab.com/mydac)