Subject Re: [firebird-support] Index suggestion
Author Arno Brinkman
Hi,

> SELECT DISTINCT AREA_ID
> FROM TMP_CKRAJ
> WHERE
> (ID_CCOUNTRY = 'CZE') AND
> (NAME_TYPE = 'B')
> GROUP BY AREA_ID
> HAVING
> (COUNT(AREA_ID) > 1)
>
> It's easy to make an index for ID_CCOUNTRY and NAME_TYPE, but is there
> any chance to help engine with index that can be used for DISTINCT/GROUP
> BY/HAVING COUNT ?

Compound index on (ID_CCOUNTRY, NAME_TYPE) looks most usefull to me, but i don't see the usage of DISTINCT in your query
here.

Also think of the next possible approach for your query:

SELECT
aa.AREA_ID
FROM
Table_All_Area aa
WHERE
EXISTS(SELECT 1 FROM TMP_CKRAJ tc WHERE
tc.ID_CCOUNTRY = 'CZE' and
tc.NAME_TYPE = 'B' and
tc.AREA_ID = aa.AREA_ID)

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database with many powerful SQL features:
http://www.firebirdsql.org
http://www.firebirdsql.info

General database developer support:
http://www.databasedevelopmentforum.com

Support list for Interbase and Firebird users:
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep:
news://newsgroups.firebirdsql.info