Skip to content
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

Equality predicate distribution does not work for some complex queries [CORE4365] #4687

Closed
firebird-issue-importer opened this issue Mar 15, 2014 · 6 comments

Comments

@firebird-issue-importer

Submitted by: @dmitry-starodubov

Is related to QA595

Artificial test case:

set planonly;

select * from (
select rdb$relation_id as id
from rdb$relations r
join (
select rdb$generator_id as id from rdb$generators
union all
select rdb$generator_id as id from rdb$generators
) rf on http://rf.id = r.rdb$relation_id
) where id = 1

PLAN JOIN (RF RDB$GENERATORS INDEX (RDB$INDEX_46), RF RDB$GENERATORS INDEX (RDB$INDEX_46), R INDEX (RDB$INDEX_1))

Note that "id = 1" means "r.rdb$relation_id = 1", given both this boolean and "http://rf.id = r.rdb$relation_id", the optimizer derives "http://rf.id = 1" that can be pushed inside the union to become "rdb$generator_id = 1" thus using indices for filtering. So far so good.

select * from (
select rdb$relation_id as id
from rdb$relations r
join (
select rdb$generator_id as id from rdb$generators
union all
select rdb$generator_id as id from rdb$generators
) rf on http://rf.id = r.rdb$relation_id
left join rdb$procedures p on p.rdb$procedure_id = http://rf.id
) where id = 1

PLAN JOIN (JOIN (RF RDB$GENERATORS NATURAL, RF RDB$GENERATORS NATURAL, R INDEX (RDB$INDEX_1)), P INDEX (RDB$INDEX_22))

And here we see that an extra unrelated join completely breaks equality distribution so that no new boolean is injected and no indices are used inside the union.

Expected plan:
PLAN JOIN (JOIN (RF RDB$GENERATORS INDEX (RDB$INDEX_46), RF RDB$GENERATORS INDEX (RDB$INDEX_46), R INDEX (RDB$INDEX_1)), P INDEX (RDB$INDEX_22))

Commits: 383b484 FirebirdSQL/fbt-repository@7d3dd47

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 15, 2014

Modified by: @dyemanov

reporter: Dmitry Yemanov [ dimitr ] => Dmitriy Starodubov [ dmitriy starodubov ]

assignee: Dmitry Yemanov [ dimitr ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 15, 2014

Modified by: @dyemanov

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

resolution: Fixed [ 1 ]

Fix Version: 3.0 Beta 1 [ 10332 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 29, 2014

Modified by: @pcisar

Link: This issue is related to QA595 [ QA595 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented May 28, 2015

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: Done successfully

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 23, 2015

Commented by: @pcisar

Test created.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 23, 2015

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment