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

Cardinality estimation should use primary record versions only #8161

Closed
hvlad opened this issue Jun 18, 2024 · 1 comment · Fixed by #8162
Closed

Cardinality estimation should use primary record versions only #8161

hvlad opened this issue Jun 18, 2024 · 1 comment · Fixed by #8162

Comments

@hvlad
Copy link
Member

hvlad commented Jun 18, 2024

The issue was found on FB3 due to failed QA test for CORE-5602.
While the test runs successfully on FB4-FB6, the issue is common for all versions.

The test case uses database backup from QA test for CORE-5602.

The test query:

execute block
as
declare relname varchar(32);
declare cnt int;
begin
  for select X.RDB$RELATION_NAME
        from RDB$RELATION_FIELDS X
       where X.RDB$FIELD_SOURCE = 'BOOL_EMUL'
      into :relname
  do begin
     select count(*)
       from RDB$DEPENDENCIES DEP, RDB$PROCEDURES PRC
      where DEP.RDB$DEPENDED_ON_NAME = :relname
        AND DEP.RDB$FIELD_NAME = :relname
        AND DEP.RDB$DEPENDED_ON_TYPE = 0 /* obj_relation */
        AND DEP.RDB$DEPENDENT_TYPE = 5 /* obj_procedure */
        AND DEP.RDB$DEPENDENT_NAME = PRC.RDB$PROCEDURE_NAME
        AND PRC.RDB$PACKAGE_NAME IS NULL
    into :cnt;
  end
end

Bad plan and stats:

PLAN JOIN (PRC INDEX (RDB$INDEX_21), DEP INDEX (RDB$INDEX_27, RDB$INDEX_28))
PLAN (X INDEX (RDB$INDEX_3))

Execute : 94,00 ms
Fetches: 164 751

Table Name Indexed reads
RDB$DEPENDENCIES 27000
RDB$INDICES 9
RDB$PROCEDURES 27000
RDB$RELATION_FIELDS 900

Good plan and stats:

PLAN JOIN (DEP INDEX (RDB$INDEX_28), PRC INDEX (RDB$INDEX_21))
PLAN (X INDEX (RDB$INDEX_3))

Execute : 47,00 ms
Fetches: 29 746

Table Name Indexed reads
RDB$DEPENDENCIES 27000
RDB$INDICES 7
RDB$RELATION_FIELDS 900

@hvlad hvlad self-assigned this Jun 18, 2024
hvlad added a commit that referenced this issue Jun 18, 2024
hvlad added a commit that referenced this issue Jun 18, 2024
Improvement #8161 : Cardinality estimation should use primary record versions only
@tomaszdubiel18
Copy link

I find this fix to be extremely usefull. I have already a few cases when a complex SELECT ran for a few minutes, while on 3.0.12 the results are almost immediate. Thanks!

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