Skip to content

planner: wrong Join estimation depending on uninitialized or missing stats #61602

@qw4990

Description

@qw4990

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Root Cause:
1. In join estimation, we use left-rows*right-rows/max(left-ndv, right-ndv).
2. When deriving NDV from index-stats, we didn't check whether it was loaded or missing. After adding a new index without analyzing, the index-stats might be missing,
3. If it's missing, we'll use the wrong NDV=0 or 1 to calculate join estimation, and finally get a high error result.

See the pic below, the join estimation has a huge error:

Image

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

v7.5.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.epic/cardinality-estimationthe optimizer cardinality estimationreport/customerCustomers have encountered this bug.severity/majorsig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions