Subject | Re: How to plan a query |
---|---|
Author | danyschaer |
Post date | 2008-12-09T19:39:35Z |
Hi Dmitry;
Here you have my test, with an index like the one I am testing in
Postgres, but in descending order as you sugested; Firebird still
does not use it.
Please let me know if you have any other idea, and thank you !!
Dany
CREATE TABLE MOVI
(
MOVI Char(10) NOT NULL,
PROC Char(10) NOT NULL,
MIEM Char(10) NOT NULL,
TIPO Char(1) NOT NULL,
AVIS Char(2) NOT NULL,
HECH Char(1) NOT NULL,
FECH Char(8) NOT NULL,
HORA Char(4) NOT NULL,
DSCR Varchar(200) NOT NULL,
FOJA Varchar(10) NOT NULL,
PRES Char(1) NOT NULL,
TEXT Blob sub_type 0,
CONSTRAINT MOVI_PK PRIMARY KEY (MOVI)
);
CREATE INDEX MOVI_FECH ON MOVI (FECH,HORA);
CREATE INDEX MOVI_HECH ON MOVI (HECH);
CREATE INDEX MOVI_MIEM ON MOVI (MIEM);
CREATE INDEX MOVI_PRES ON MOVI (PRES);
CREATE DESCENDING INDEX MOVI_PRFH ON MOVI (PROC,FECH);
CREATE INDEX MOVI_PROC ON MOVI (PROC);
CREATE INDEX MOVI_TIPO ON MOVI (TIPO);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON MOVI TO LEX WITH GRANT OPTION;
Starting transaction...
Preparing query: select m1."PROC",m1."FECH",m1."HORA",m1."DSCR"
from "MOVI" m1 where m1."FECH"=(select max(m2."FECH") from "MOVI" m2
where m1."PROC"=m2."PROC" and m2."TIPO" = '1' and m2."HECH" = 'P')
and m1."TIPO" = '1' and m1."HECH" = 'P'
Prepare time: 00:00:01.
Field #01: MOVI.PROC Alias:PROC Type:STRING(10)
Field #02: MOVI.FECH Alias:FECH Type:STRING(8)
Field #03: MOVI.HORA Alias:HORA Type:STRING(4)
Field #04: MOVI.DSCR Alias:DSCR Type:STRING(200)
PLAN (M2 INDEX (MOVI_PROC))
PLAN (M1 INDEX (MOVI_TIPO, MOVI_HECH))
Script execution finished.
Here you have my test, with an index like the one I am testing in
Postgres, but in descending order as you sugested; Firebird still
does not use it.
Please let me know if you have any other idea, and thank you !!
Dany
CREATE TABLE MOVI
(
MOVI Char(10) NOT NULL,
PROC Char(10) NOT NULL,
MIEM Char(10) NOT NULL,
TIPO Char(1) NOT NULL,
AVIS Char(2) NOT NULL,
HECH Char(1) NOT NULL,
FECH Char(8) NOT NULL,
HORA Char(4) NOT NULL,
DSCR Varchar(200) NOT NULL,
FOJA Varchar(10) NOT NULL,
PRES Char(1) NOT NULL,
TEXT Blob sub_type 0,
CONSTRAINT MOVI_PK PRIMARY KEY (MOVI)
);
CREATE INDEX MOVI_FECH ON MOVI (FECH,HORA);
CREATE INDEX MOVI_HECH ON MOVI (HECH);
CREATE INDEX MOVI_MIEM ON MOVI (MIEM);
CREATE INDEX MOVI_PRES ON MOVI (PRES);
CREATE DESCENDING INDEX MOVI_PRFH ON MOVI (PROC,FECH);
CREATE INDEX MOVI_PROC ON MOVI (PROC);
CREATE INDEX MOVI_TIPO ON MOVI (TIPO);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON MOVI TO LEX WITH GRANT OPTION;
Starting transaction...
Preparing query: select m1."PROC",m1."FECH",m1."HORA",m1."DSCR"
from "MOVI" m1 where m1."FECH"=(select max(m2."FECH") from "MOVI" m2
where m1."PROC"=m2."PROC" and m2."TIPO" = '1' and m2."HECH" = 'P')
and m1."TIPO" = '1' and m1."HECH" = 'P'
Prepare time: 00:00:01.
Field #01: MOVI.PROC Alias:PROC Type:STRING(10)
Field #02: MOVI.FECH Alias:FECH Type:STRING(8)
Field #03: MOVI.HORA Alias:HORA Type:STRING(4)
Field #04: MOVI.DSCR Alias:DSCR Type:STRING(200)
PLAN (M2 INDEX (MOVI_PROC))
PLAN (M1 INDEX (MOVI_TIPO, MOVI_HECH))
Script execution finished.