Subject | Can this be optimized |
---|---|
Author | Stefan Heymann |
Post date | 2006-05-19T12:24:26Z |
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
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