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

Sub-optimal join plan when the slave table depends on the master one via the OR predicate [CORE3312] #3679

Closed
firebird-issue-importer opened this issue Jan 20, 2011 · 7 comments

Comments

@firebird-issue-importer

Submitted by: @pavel-zotov

Is related to QA454

Test case:

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class)
-- Good plan:
-- PLAN JOIN (R NATURAL, SC INDEX (RDB$INDEX_7))

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class
or r.rdb$default_class = sc.rdb$security_class)
-- Bad plan:
-- PLAN JOIN (R NATURAL, SC NATURAL)
-- Expected plan:
-- PLAN JOIN (R NATURAL, SC INDEX (RDB$INDEX_7, RDB$INDEX_7))

An attempt to specify the expected plan manually throws an error:
-- index RDB$INDEX_7 cannot be used in the specified plan

A prerequisite is that the slave index must be unique.

One more example is below. In fact, this is a bit different issue, although related and thus can be described by the same ticket.

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class and r.rdb$relation_id = 0)
or (r.rdb$default_class = sc.rdb$security_class and r.rdb$relation_id = 1)
-- Reported (bad) plan:
-- PLAN JOIN (R INDEX (RDB$INDEX_1, RDB$INDEX_1), SC NATURAL)
-- Expected plan:
-- PLAN JOIN (R INDEX (RDB$INDEX_1, RDB$INDEX_1), SC INDEX (RDB$INDEX_7, RDB$INDEX_7))

This time the prerequisite is that the OR predicate has two ANDed sub-conditions and one of them (filter) is indexable for the master table.

Commits: 6e6d341 e0648e8 0005a71 FirebirdSQL/fbt-repository@cdc627b

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 20, 2011

Modified by: @dyemanov

reporter: Dmitry Yemanov [ dimitr ] => Pavel Zotov [ tabloid ]

assignee: Dmitry Yemanov [ dimitr ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 20, 2011

Modified by: @dyemanov

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 20, 2011

Modified by: @dyemanov

description: Test case:

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class)
-- Good plan:
-- PLAN JOIN (R NATURAL, SC INDEX (RDB$INDEX_7))

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class
or r.rdb$default_class = sc.rdb$security_class)
-- Bad plan:
-- PLAN JOIN (R NATURAL, SC NATURAL)
-- Expected plan:
-- PLAN JOIN (R NATURAL, SC INDEX (RDB$INDEX_7, RDB$INDEX_7))

An attempt to specify the expected plan manually throws an error:
-- index RDB$INDEX_7 cannot be used in the specified plan

A prerequisite is that the slave index must be unique.

=>

Test case:

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class)
-- Good plan:
-- PLAN JOIN (R NATURAL, SC INDEX (RDB$INDEX_7))

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class
or r.rdb$default_class = sc.rdb$security_class)
-- Bad plan:
-- PLAN JOIN (R NATURAL, SC NATURAL)
-- Expected plan:
-- PLAN JOIN (R NATURAL, SC INDEX (RDB$INDEX_7, RDB$INDEX_7))

An attempt to specify the expected plan manually throws an error:
-- index RDB$INDEX_7 cannot be used in the specified plan

A prerequisite is that the slave index must be unique.

One more example is below. In fact, this is a bit different issue, although related and thus can be described by the same ticket.

select *
from rdb$relations r
join rdb$security_classes sc
on (r.rdb$security_class = sc.rdb$security_class and r.rdb$relation_id = 0)
or (r.rdb$default_class = sc.rdb$security_class and r.rdb$relation_id = 1)
-- Reported (bad) plan:
-- PLAN JOIN (R INDEX (RDB$INDEX_1, RDB$INDEX_1), SC NATURAL)
-- Expected plan:
-- PLAN JOIN (R INDEX (RDB$INDEX_1, RDB$INDEX_1), SC INDEX (RDB$INDEX_7, RDB$INDEX_7))

This time the prerequisite is that the OR predicate has two ANDed sub-conditions and one of them (filter) is indexable for the master table.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 29, 2011

Modified by: @dyemanov

status: In Progress [ 3 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.5.1 [ 10333 ]

Fix Version: 3.0 Alpha 1 [ 10331 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 24, 2011

Modified by: @pcisar

Link: This issue is related to QA454 [ QA454 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jun 4, 2013

Modified by: @pmakowski

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

Fix Version: 3.0 Alpha 1 [ 10331 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jul 16, 2015

Modified by: @pavel-zotov

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

QA Status: Done successfully

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