Subject | RE: [firebird-support] Can this be optimized |
---|---|
Author | Paul Mercea |
Post date | 2006-05-19T12:30:45Z |
Hi
U can use
Select first 1 * from employee order by hire_date desc
Regards
Paul
|-----Original Message-----
|From: firebird-support@yahoogroups.com [mailto:firebird-
|support@yahoogroups.com] On Behalf Of Stefan Heymann
|Sent: Friday, May 19, 2006 3:24 PM
|To: firebird-support@yahoogroups.com
|Subject: [firebird-support] Can this be optimized
|
|Hello,
|
|let's assume I have employee.fdb and want to know the employee that
|was hired last.
|
|I use the following SELECT for that:
|
| select * from employee
| where hire_date = (select max (hire_date) from employee)
|
|
|The PLAN that's created for this looks quite dramatic:
| PLAN (EMPLOYEE NATURAL) PLAN (EMPLOYEE NATURAL)
|
|When I create an index on the HIRE_DATE field, the PLAN becomes:
| PLAN (EMPLOYEE NATURAL) PLAN (EMPLOYEE INDEX (IDX_EMPLOYEE_HIRE))
|
|Is there another, more efficient way to express that SELECT?
|
|The background: I have an application where I will very often have to
|look for the "latest" record (MAX (datetime), where datetime is a
|TIMESTAMP field) and I don't want to create too much work for the
|server with that.
|
|
|Best Regards
|
|Stefan
|
|
|
|
|
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|Visit http://firebird.sourceforge.net and click the Resources item
|on the main (top) menu. Try Knowledgebase and FAQ links !
|
|Also search the knowledgebases at http://www.ibphoenix.com
|
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|Yahoo! Groups Links
|
|
|
|
|
U can use
Select first 1 * from employee order by hire_date desc
Regards
Paul
|-----Original Message-----
|From: firebird-support@yahoogroups.com [mailto:firebird-
|support@yahoogroups.com] On Behalf Of Stefan Heymann
|Sent: Friday, May 19, 2006 3:24 PM
|To: firebird-support@yahoogroups.com
|Subject: [firebird-support] Can this be optimized
|
|Hello,
|
|let's assume I have employee.fdb and want to know the employee that
|was hired last.
|
|I use the following SELECT for that:
|
| select * from employee
| where hire_date = (select max (hire_date) from employee)
|
|
|The PLAN that's created for this looks quite dramatic:
| PLAN (EMPLOYEE NATURAL) PLAN (EMPLOYEE NATURAL)
|
|When I create an index on the HIRE_DATE field, the PLAN becomes:
| PLAN (EMPLOYEE NATURAL) PLAN (EMPLOYEE INDEX (IDX_EMPLOYEE_HIRE))
|
|Is there another, more efficient way to express that SELECT?
|
|The background: I have an application where I will very often have to
|look for the "latest" record (MAX (datetime), where datetime is a
|TIMESTAMP field) and I don't want to create too much work for the
|server with that.
|
|
|Best Regards
|
|Stefan
|
|
|
|
|
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|Visit http://firebird.sourceforge.net and click the Resources item
|on the main (top) menu. Try Knowledgebase and FAQ links !
|
|Also search the knowledgebases at http://www.ibphoenix.com
|
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|Yahoo! Groups Links
|
|
|
|
|