New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query optimizer in 2.5.8 and 3.x is not using importan index (but early 2.5 version uses it) [CORE6070] #6320
Comments
Commented by: Sean Leyne (seanleyne) Reformatted the original query for readiblity |
Modified by: Sean Leyne (seanleyne)description: Hi; On my database one table is this: CREATE TABLE MOVI The database has more than one millon records in this table and 46.000 records in table PROC. I have to do this query: select "PROC"."PROC","PROC"."CARP","PROC"."ACTO","PROC"."DEMA","PROC"."OBSE","TPRO"."DSCR" as "D_TPRO","PROC"."OJUD","PROC"."INST","PROC"."EXP1","PROC"."EXP2","PROC"."EXP3","PROC"."EXP4" from "PROC" left outer join "TPRO" on "PROC"."TPRO"="TPRO"."TPRO" left outer join "OJUD" o1 on "PROC"."OJUD"=o1."OJUD" left outer join "ZONA" o2 on o1."ZONA"=o2."ZONA" where ((("PROC"."PROC" in (select distinct "PROC" from "MOVI" where "MOVI"."TIPO" in ('1','A','B') and ("MOVI"."FECH" between '20190301' and '20190412') and "MOVI"."MIEM" = '15JMS45D7A' and "MOVI"."HECH" = 'N' order by "PROC")))) order by o2."ORDE",o1."ORDE",lower("PROC"."ACTO"),lower("PROC"."DEMA") On early 2.5.x versions, this query need up to 1 minute in the test machine to finish, but the same machine 2.5.8 and 3.x are using more than 20 minutes. Under 2.5.0 the query optimizer builds a plan using MOVI_FECH: PLAN SORT ((MOVI INDEX (MOVI_PROC, MOVI_FECH))) But under 2.5.8 the query optimizer does not use MOVI_FECH PLAN SORT ((MOVI INDEX (MOVI_PROC))) I found that 2.5.8 only uses MOVI_FECH if I do ("MOVI"."FECH" = '20190301') but it does not use that index if I use between or if I use >= and/or <=. I thing this is the problem that makes my query to need 20 minutes instead of 1 minute. Thank you. => Hi; On my database one table is this: CREATE TABLE MOVI The database has more than one millon records in this table and 46.000 records in table PROC. I have to do this query: select On early 2.5.x versions, this query need up to 1 minute in the test machine to finish, but the same machine 2.5.8 and 3.x are using more than 20 minutes. Under 2.5.0 the query optimizer builds a plan using MOVI_FECH: PLAN SORT ((MOVI INDEX (MOVI_PROC, MOVI_FECH))) But under 2.5.8 the query optimizer does not use MOVI_FECH PLAN SORT ((MOVI INDEX (MOVI_PROC))) I found that 2.5.8 only uses MOVI_FECH if I do ("MOVI"."FECH" = '20190301') but it does not use that index if I use between or if I use >= and/or <=. I thing this is the problem that makes my query to need 20 minutes instead of 1 minute. Thank you. |
Commented by: Sean Leyne (seanleyne) This is a support question which should have been posted to the Firebird support mailing list, not posted to this tracker. The use of The optimal syntax would be:
Please try this syntax and advise. Further, depending on the manner in which you normally would query "MOVI" rows, you should consider creating a new compound index on the table combining "PROC", "MIEM", "FECH" (with the fields ordered from least to most specific/selective). That would also improve the performance of the query |
Commented by: Daniel (danyschaer) Before asking here, I already was testing your suggestion: select This sintaxys DOES NOT make any diference in performance. That means, it is very fast in early 2.5 but it is the same slow under 2.5.8. Here you have the resulting plan under 2.5.8: Preparing query: select It is absolutely clear it is a problem, and not a "support question". 20 minutes ... |
Commented by: Daniel (danyschaer) I found where is the problem. This is not about using "IN". The thing is very simple: From Firebird 2.5.0 to Firebird 2.5.3 the query optimizer uses the compound index MOVI_FECH (FECH,HORA) ; but from Firebird 2.5.4 the query optimizer does not use this compound index anymore. If under 2.5.8 I add now a new index for FECH, then the query optimizer uses it, and the query is faster again. Why the optimizer does not use the compound index MOVI_FECH after Firebird 2.5.3 ?? And please!!! note that if with FB 2.5.8 I only do the MOVI part of the query, then the optimizer uses MOVI_FECH: Starting transaction... Which means that MOVI_FECH is usefull. And it also uses MOVI_MIEM !!! |
Submitted by: Daniel (danyschaer)
Hi;
On my database one table is this:
CREATE TABLE MOVI
(
MOVI Char(10) NOT NULL COLLATE ES_ES_AI,
PROC Char(10) NOT NULL COLLATE ES_ES_AI,
MIEM Char(10) NOT NULL COLLATE ES_ES_AI,
TIPO Char(1) NOT NULL COLLATE ES_ES_AI,
AVIS Char(3) NOT NULL COLLATE ES_ES_AI,
HECH Char(1) NOT NULL COLLATE ES_ES_AI,
FECH Char(8) NOT NULL COLLATE ES_ES_AI,
HORA Char(4) NOT NULL COLLATE ES_ES_AI,
DSCR Varchar(200) NOT NULL COLLATE ES_ES_AI,
FOJA Varchar(10) NOT NULL COLLATE ES_ES_AI,
PRES Char(1) NOT NULL COLLATE ES_ES_AI,
REPI Char(1) NOT NULL COLLATE ES_ES_AI,
OWNR Char(10) NOT NULL COLLATE ES_ES_AI,
TEXT Blob sub_type 0,
"EDIT" Char(23) NOT NULL COLLATE ES_ES_AI,
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_OWNR ON MOVI (OWNR);
CREATE INDEX MOVI_PRES ON MOVI (PRES);
CREATE INDEX MOVI_PROC ON MOVI (PROC);
CREATE INDEX MOVI_REPI ON MOVI (REPI);
CREATE INDEX MOVI_TIPO ON MOVI (TIPO);
The database has more than one millon records in this table and 46.000 records in table PROC. I have to do this query:
select
"PROC"."PROC", "PROC"."CARP", "PROC"."ACTO", "PROC"."DEMA", "PROC"."OBSE", "TPRO"."DSCR" as "D_TPRO",
"PROC"."OJUD", "PROC"."INST", "PROC"."EXP1", "PROC"."EXP2", "PROC"."EXP3", "PROC"."EXP4"
from "PROC"
left outer join "TPRO" on "PROC"."TPRO" = "TPRO"."TPRO"
left outer join "OJUD" O1 on "PROC"."OJUD" = O1."OJUD"
left outer join "ZONA" O2 on O1."ZONA" = O2."ZONA"
where
(
(
("PROC"."PROC" in (
select distinct "PROC"
from "MOVI"
where
"MOVI"."TIPO" in ('1', 'A', 'B')
and ("MOVI"."FECH" between '20190301' and '20190412')
and "MOVI"."MIEM" = '15JMS45D7A'
and "MOVI"."HECH" = 'N'
order by "PROC"
)
)
)
)
order by O2."ORDE", O1."ORDE", lower("PROC"."ACTO"), lower("PROC"."DEMA")
On early 2.5.x versions, this query need up to 1 minute in the test machine to finish, but the same machine 2.5.8 and 3.x are using more than 20 minutes.
Under 2.5.0 the query optimizer builds a plan using MOVI_FECH:
PLAN SORT ((MOVI INDEX (MOVI_PROC, MOVI_FECH)))
But under 2.5.8 the query optimizer does not use MOVI_FECH
PLAN SORT ((MOVI INDEX (MOVI_PROC)))
I found that 2.5.8 only uses MOVI_FECH if I do ("MOVI"."FECH" = '20190301') but it does not use that index if I use between or if I use >= and/or <=.
I thing this is the problem that makes my query to need 20 minutes instead of 1 minute.
Thank you.
The text was updated successfully, but these errors were encountered: