Subject | Re: FireBird : Table Setup, Views and Slow Queries |
---|---|
Author | Svein Erling |
Post date | 2004-04-13T10:18:47Z |
> select PROPERTIES.AGENT_REFERENCE,ENTITY_ID),
> OWNERS.SURNAME as OWNER_SURNAME, OWNERS.INITIALS as
> OWNER_INITIALS, OWNERS.NAME as OWNER_NAME, OWNERS.COMPANY_NAME as
> OWNER_COMPANY_NAME,
> BUYERS.SURNAME as BUYER_SURNAME, BUYERS.INITIALS as
> BUYER_INITIALS, BUYERS.NAME as BUYER_NAME, BUYERS.COMPANY_NAME as
> BUYER_COMPANY_NAME,
> PROPERTIES.ADDRESS_ROAD,
> 'xxxxx' as OUR_REFERENCE /*Calculated via another process*/,
> INSPECTIONS.DATE_INSPECTED,
> COMPANIES.ELECTRICAL_INSPECTION_COMM as COMMISSION
> from INSPECTIONS, PROPERTIES,
> PROPERTY_OWNERS
> left join OWNERS on (OWNERS.ENTITY_ID = PROPERTY_OWNERS.
> PROPERTY_BUYERSENTITY_ID),
> left join BUYERS on (BUYERS.ENTITY_ID = PROPERTY_BUYERS.
> PROPERTY_AGENTSENTITY_ID)
> left join AGENTS on (AGENTS.ENTITY_ID = PROPERTY_AGENTS.
> left join COMPANIES on (COMPANIES.ID = AGENTS.COMPANY_ID)What a mess! Using SQL-89 with the addition of LEFT JOIN (SQL-92) like
> where INSPECTIONS.INSPECTION_ID = 23 and
> INSPECTIONS.SERVICE_TYPE = 1 and
> PROPERTIES.ID = INSPECTIONS.PROPERTY_ID and
> PROPERTY_OWNERS.PROPERTY_ID = PROPERTIES.ID and
> PROPERTY_BUYERS.PROPERTY_ID = PROPERTIES.ID and
> PROPERTY_AGENTS.PROPERTY_ID = PROPERTIES.ID
this certainly confuses me. Rewrite to using only SQL-92 (i.e. don't
use any commas in the WHERE part, but stick to JOIN and LEFT JOIN).
> PLAN JOIN (MERGE (SORT (JOIN (JOIN (PROPERTY_AGENTS INDEXPERSONS
> (PROPERTY_AGENTS_IDX1),JOIN (JOIN (JOIN (JOIN (AGENTS ENTITIES INDEX
> (RDB$PRIMARY1),AGENTS ENTITY_TYPES INDEX (RDB$PRIMARY2)),AGENTS
> INDEX (RDB$PRIMARY4)),AGENTS COMPANIES INDEX (RDB$PRIMARY5)),AGENTSPERSONS
> ENTITY_ROLES INDEX (RDB$PRIMARY3))),COMPANIES INDEX
> (RDB$PRIMARY5))),SORT (JOIN (PROPERTY_BUYERS INDEX
> (PROPERTY_BUYERS_IDX1),JOIN (JOIN (JOIN (JOIN (BUYERS ENTITIES INDEX
> (RDB$PRIMARY1),BUYERS ENTITY_TYPES INDEX (RDB$PRIMARY2)),BUYERS
> INDEX (RDB$PRIMARY4)),BUYERS COMPANIES INDEX (RDB$PRIMARY5)),BUYERSPERSONS
> ENTITY_ROLES INDEX (RDB$PRIMARY3)))),SORT (JOIN (PROPERTY_OWNERS
> NATURAL,JOIN (JOIN (JOIN (JOIN (OWNERS ENTITIES INDEX
> (RDB$PRIMARY1),OWNERS ENTITY_TYPES INDEX (RDB$PRIMARY2)),OWNERS
> INDEX (RDB$PRIMARY4)),OWNERS COMPANIES INDEX (RDB$PRIMARY5)),OWNERSI assume that any slowness comes from PROPERTY_OWNERS NATURAL, it may
> ENTITY_ROLES INDEX (RDB$PRIMARY3))))),JOIN (INSPECTIONS INDEX
> (INSPECTIONS_IDX2),PROPERTIES INDEX (FK_PROPERTIES)))
be easier to tell once we see the fixed SQL and whether the plan is
still the same or not.
HTH,
Set