Subject Re: [firebird-support] Re: AGAIN (i know, but different) Max optimized... or not?
Author Christian Mereles
Ok, some querys:

1 - No index:

select coalesce(max(o.N_ORDEN), 0) + 1 from ORDENES O
where O.EJER=2012 --into new.n_orden

https://dl.dropboxusercontent.com/u/15932768/sin_indice.jpg

2 - With index, uses multiple records:

create descending index ordenes_idx1 on ordenes (ejer,n_orden);
select coalesce(max(o.N_ORDEN), 0) + 1 from ORDENES O
where O.EJER=2012

https://dl.dropboxusercontent.com/u/15932768/usa_indice_muchos.jpg

3 - With index, use only 1 record:

create descending index ordenes_idx1 on ordenes (ejer,n_orden);
select first 1 coalesce(o.n_orden,0) + 1 from ordenes o
where o.ejer=2012
order by o.ejer desc, o.n_orden desc
--into new.n_orden;

https://dl.dropboxusercontent.com/u/15932768/usa_indice_uno.jpg

Regards.

Christian.


[Non-text portions of this message have been removed]