Subject Re: [firebird-support] Looking for advice on indexes
Author Marcin Bury
Sean

W dniu 03.05.2013 19:18, Leyne, Sean pisze:
> Marcin,
>
>> I have following table named TSH:
>>
>> ID INTEGER
>> SITE VARCHAR(50)
>> WORK_DATE DATE
>>
>> each day there are 10 up to 15 records inserted with various sites.
>> The list of sites is quite limited and consists of around 50 items.
>>
>> Then I have following query
>>
>> SELECT SITE_ID, MAX(WORK_DATE)
>> FROM TSH
>> GROUP BY 1
>>
>> to get the latest entry for each site
>>
>> What indexes should I create to get this query as quickest as possible?
>
> For this query, a DESCENDING compound index with the ID and WORK_DATE would be best.
>
Are you sure that it should be ID not SITE_ID?
I've created DESCENDING index for SITE_ID, WORK_DATE and it looks really
fast despite fact that all records have been read (according to IB
Expert Performance Analisys).

Thanks
Marcin