firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Non-Optimal plan for a left join c inner join b [CORE1239]

Open firebird-automations opened this issue 18 years ago • 9 comments

Submitted by: Jojakim Stahl (jstahl)

Is duplicated by CORE2937 Is duplicated by CORE2963

Votes: 4

In short: The plan for a left join c inner join b is worse than the plan for a inner join b left join c. Refer also to: http://tech.groups.yahoo.com/group/firebird-support/message/85749 (archive) which is a bit more complex than the reduced example here.

select * from t_a a left join t_c c on a.id=c.ta_id inner join t_b b on a.id=b.owner_id where b.member_id=2

results in a plan with a table scan for a: PLAN JOIN (JOIN (A NATURAL, C INDEX (PK_TC)), B INDEX (IX_TB_OWNER, IX_TB_MEMBER))

where the following select returns the same result but without table scan: select * from t_a a inner join t_b b on a.id=b.owner_id left join t_c c on a.id=c.ta_id where b.member_id=2

PLAN JOIN ( JOIN (B INDEX (IX_TB_MEMBER), A INDEX (PK_TA)), C INDEX (PK_TC))

Script for setting up test database: create table t_a ( id integer not null, uid integer not null );

create table t_b ( owner_id integer not null, member_id integer );

create table t_c ( ta_id integer not null, sub_id integer not null );

insert into t_a (id, uid) values (1, 100); insert into t_a (id, uid) values (2, 200); insert into t_a (id, uid) values (3, 300);

commit work;

insert into t_b (owner_id, member_id) values (1, 2); insert into t_b (owner_id, member_id) values (1, null); insert into t_b (owner_id, member_id) values (3, 1);

commit work;

insert into t_c (ta_id, sub_id) values (3, 1); insert into t_c (ta_id, sub_id) values (3, 2);

commit work;

alter table t_a add constraint pk_ta primary key (id); alter table t_c add constraint pk_tc primary key (ta_id, sub_id);

create index ix_ta_uid on t_a (uid); create index ix_tb_member on t_b (member_id); create index ix_tb_owner on t_b (owner_id);

====== Test Details ======

Deferred until changes in optimizer will be done. Test will be common for this ticket and core-2963

firebird-automations avatar May 03 '07 08:05 firebird-automations

Modified by: @dyemanov

assignee: Dmitry Yemanov [ dimitr ]

firebird-automations avatar Nov 13 '07 06:11 firebird-automations

Modified by: @pcisar

Workflow: jira [ 12000 ] => Firebird [ 15558 ]

firebird-automations avatar Jan 28 '08 15:01 firebird-automations

Modified by: @dyemanov

Link: This issue is duplicated by CORE2937 [ CORE2937 ]

firebird-automations avatar Mar 23 '10 10:03 firebird-automations

Modified by: @dyemanov

Link: This issue is duplicated by CORE2963 [ CORE2963 ]

firebird-automations avatar Apr 11 '10 08:04 firebird-automations

Modified by: @dyemanov

Fix Version: 3.0 Alpha 1 [ 10331 ]

firebird-automations avatar Jul 23 '10 12:07 firebird-automations

Modified by: @dyemanov

Fix Version: 3.0 Beta 1 [ 10332 ]

Fix Version: 3.0 Alpha 1 [ 10331 ] =>

firebird-automations avatar Oct 23 '12 10:10 firebird-automations

Modified by: @dyemanov

Fix Version: 3.0 Beta 2 [ 10586 ]

Fix Version: 3.0 Beta 1 [ 10332 ] =>

firebird-automations avatar Apr 24 '14 15:04 firebird-automations

Modified by: @dyemanov

Fix Version: 3.0 Beta 2 [ 10586 ] =>

firebird-automations avatar Oct 16 '14 18:10 firebird-automations

Modified by: @pavel-zotov

status: Open [ 1 ] => Open [ 1 ]

QA Status: Deferred

Test Details: Deferred until changes in optimizer will be done. Test will be common for this ticket and core-2963

firebird-automations avatar Nov 21 '16 22:11 firebird-automations