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
Performance with Subselect containing Group-By [CORE1034] #1451
Comments
Modified by: Baldur F?rchau (fuerchau)description: I have to tables, each with about 200.000 Records. Now i code the following SQL: select * from The Resultset contains ca. 100 Records. If i create 2 temporary tables insert into xtablea insert into xtable5 select * from xtablea left join xtableb on a.k1=b.k1 and a.k2=b.k2 and a.k3=b.k3 the answertime is about 8 seconds !!!! So, why can't Firebird do this automatic ? => I have to tables, each with about 200.000 Records. Now i code the following SQL: select * from The Resultset contains ca. 100 Records. If i create 2 temporary tables insert into xtablea insert into xtable5 select * from xtablea left join xtableb on a.k1=b.k1 and a.k2=b.k2 and a.k3=b.k3 the answertime is about 8 seconds !!!! I think, firebird solve this with "temporary views" instead of "temporary table". So, why can't Firebird do use automatic "temporary tables" ? |
Commented by: Sean Leyne (seanleyne) Please post the PLAN for the initial statement. |
Commented by: Sean Leyne (seanleyne) Please clarify: By 8 seconds do you mean that your can perform the INSERTs and SELECT in 8 seconds? If not, please post the total time. |
Commented by: Sean Leyne (seanleyne) Finally, you realize that your statement can be better expressed as: select The k1 and k2 values can be replaced with constants, since they are specified in the WHERE clause. |
Commented by: @pcisar I have deleted the previous comment and reinserted it with access rights for FB developers only, as the original poster requested restricted access to it, but failed to assign proper access right to his comment. ---------------- Table 1: /******************************************************************************/ SET SQL DIALECT 3; SET NAMES NONE; /******************************************************************************/ CREATE TABLE UMDATEN ( /******************************************************************************/ CREATE DESCENDING INDEX UMDATEN_DLEVEL0 ON UMDATEN (LEVEL0); /******************************************************************************/ Table 2 /******************************************************************************/ SET SQL DIALECT 3; SET NAMES NONE; /******************************************************************************/ CREATE TABLE AEDATEN ( /******************************************************************************/ CREATE DESCENDING INDEX AEDATEN_DLEVEL0 ON AEDATEN (LEVEL0); /******************************************************************************/ The original SQL with IB-Expert select a.*, b.* Table AEDaten contains 252394 Records Output from SQL-Monitor [30.11.2006 20:12:27.975] : [Execute] [30.11.2006 20:12:46.362] : [Fetch] And now i'm wondering !!! Output from IB-Expert Plan: Adapted plan: Resultset contains 205 Records (this is correct). And now the responsetimes from my application: First Insert/Select from AEDaten 4,036 Seconds, Resultset 206 Records Join-Query with 205-Records 0,161 Seconds Responsetime including Create Tables and Index 6,87 Seconds !!! I don't know the reason, why the Firebird-Engine answers for the Main-Select now in 19 Seconds ?! But, i am faster with my own solution, solved for Firebird 1.5 because Views don't work so fast. Additional Informations: With Level1='001' are 283996 Records processed (sum from both tables, i don't have this from each one). In the second example my responsetime is 0,551 It seams near the same. 2. additional information. I think, i found the reason for the long time response. [30.11.2006 20:37:09.155] : [Execute] This are only 5 Minutes, but i think that a cache is active when i retrieve the same data often. Here the changed select: select a.*, b.* select a.*, b.* The additional subselect's Count(*) i don't need in my application. A word to my application: I have programmed a new Cube-Analysis-Report and this work's very fast and robust with your Firebird 1.5 ! I have solved some problems by insert/select with temporary tables, but this currupts sometimes the garbage so i must save/restore the database with gbak (known 1.5-Problem). So my hopeness is, that i make combined select's "select from (select ...)" with up to 10 and more tables, because the temporary created tables are created and delete every time the user change his report. Puh, i hope you have enough informations, and sorry about my english. If you understand german, have a look to http://www.ftsolutions.de, there is a short description of the program. |
Modified by: @pcisarWorkflow: jira [ 11368 ] => Firebird [ 15397 ] |
Submitted by: Baldur F?rchau (fuerchau)
I have to tables, each with about 200.000 Records.
Now i code the following SQL:
select * from
(select k1, k2, k3, sum(v1) as v1
from atable
where k1='1' and K2='1'
group by 1, 2, 3
) a
left join
(select k1, k2, k3, sum(v1) as v1
from btable
where k1='1' and K2='1'
group by 1, 2, 3
) b on a.k1=b.k1 and a.k2=b.k2 and a.k3=b.k3
The Resultset contains ca. 100 Records.
The Querytime is 8 Minutes !!!
If i create 2 temporary tables
XTablea, XTableb
and make the following SQL's:
insert into xtablea
select k1, k2, k3, sum(v1) as v1
from atable
where k1='1' and K2='1'
group by 1, 2, 3
insert into xtable5
select k1, k2, k3, sum(v1) as v1
from btable
where k1='1' and K2='1'
group by 1, 2, 3
select * from xtablea left join xtableb on a.k1=b.k1 and a.k2=b.k2 and a.k3=b.k3
the answertime is about 8 seconds !!!!
I think, firebird solve this with "temporary views" instead of "temporary table".
In Firebird 1.5 i tried this obove with views an i have the same query-time 8 minutes.
So, why can't Firebird do use automatic "temporary tables" ?
The text was updated successfully, but these errors were encountered: