Subject Re: [ib-support] Help with extremely slow SQL
Author Andrew Guts
nitaligavino wrote:

>Hello all:
>
>I need some help understanding how an SQL statement is executed
>within the FB engine. Specifically, I need to understand why an SQL
>statement such as:
>
>SELECT * FROM Media WHERE MKey IN (SELECT MKey FROM MediaItem WHERE
>IState = ? GROUP BY MKey)
>
>
Why did you write "group by". There is no reason to use it wihout
aggregate function.
Specify only columns you need in select statement.
try this:

select M.MKey, ...
from MediaItem I
inner join Media M on I.MKey = M.MKey
where I.IState = ?

>Here is what the statistics are:
>
>Execution Time: 00:03:22:0488
>Prepare Time: 00:00:00:0010
>Starting Memory: 9200186
>Current Memory: 9221676
>Delta Memory: 21490
>Number of Buffers: 2048
>
I guess you should increase number of buffers. If you have enough memory
of course.

>Obviously, I have rewritten some of my queries and found better
>performance but what I need to understand is why any query,
>regardless of how complex, should take more that a few milliseconds
>to seconds when there is only 1300 rows in the db??
>
>
It also depends of size of columns, optimal indexing, and so on.

Hope it will help

Good luck

Andrew

>
>