Subject Re: [firebird-support] Re: Query runs 9 minutes - how to set indexes to optimize it
Author Dean Harding
swestner wrote:
> SELECT IwadisObje_1.BOLD_ID, IwadisObje_1.BOLD_TYPE
> FROM IwadisObject IwadisObje_1 JOIN Word Word_1 ON
> (IwadisObje_1.BOLD_ID = Word_1.indexedObject)
> WHERE (Word_1.data LIKE 'SCHAAF%')
> AND ((IwadisObje_1.BOLD_TYPE = 132) or (IwadisObje_1.BOLD_TYPE =
> 131))
> AND (not(((IwadisObje_1.visibility <> 2) and (not(EXISTS (SELECT
> Client_1.BOLD_ID
> FROM Client Client_1 JOIN IwadisObject IwadisObje_6 ON
> (Client_1.BOLD_ID = IwadisObje_6.creatorClient) JOIN
> BusinessClassesRoot BusinessCl_3 ON (Client_1.BOLD_ID =
> BusinessCl_3.BOLD_ID)
> WHERE IwadisObje_1.BOLD_ID = IwadisObje_6.BOLD_ID
> AND ((((((((((((((((((((BusinessCl_3.iwadisID = '68D3C5EE-8EDC-4E5C-
> [snip]

No matter how you look at it, that statement is insanely complex. I
believe you have a fundamental problem here, stemming from the fact that
you seem to be using an O-R mapper for something it is simply not able
to do.

It's all about using the right tool for the job. O-R mappers have their
place, but generating complex queries is most certainly *not* it. I
don't know the specifics of your O-R mapper, but I would suggest you
re-write this query by hand -- we can certainly help with that, but
trying to parse this multi-page SELECT statement and suggest indexes to
speed it up is not my idea of being productive.

Dean.