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

planner, statistics: fix the inconsistent est when table has no stats #52427

Merged
merged 5 commits into from Apr 15, 2024

Conversation

winoros
Copy link
Member

@winoros winoros commented Apr 8, 2024

What problem does this PR solve?

Issue Number: close #52426

Problem Summary:

What changed and how does it work?

The Selectivity needs a memory obj to trigger the pseudo estimation.

We add one.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 8, 2024
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Merging #52427 (215fc1f) into master (6a35d5e) will increase coverage by 2.8352%.
Report is 25 commits behind head on master.
The diff coverage is 97.5609%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #52427        +/-   ##
================================================
+ Coverage   72.2252%   75.0604%   +2.8352%     
================================================
  Files          1467       1489        +22     
  Lines        426895     436889      +9994     
================================================
+ Hits         308326     327931     +19605     
+ Misses        99450      87983     -11467     
- Partials      19119      20975      +1856     
Flag Coverage Δ
integration 51.6936% <97.5609%> (?)
unit 70.9826% <90.2439%> (-0.1332%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 60.6951% <ø> (+19.7822%) ⬆️

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 8, 2024
@@ -572,7 +572,9 @@ func CleanFakeItemsForShowHistInFlights(statsCache statstypes.StatsCache) int {
if item.IsIndex {
_, loadNeeded = tbl.IndexIsLoadNeeded(item.ID)
} else {
_, loadNeeded = tbl.ColumnIsLoadNeeded(item.ID, true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We keep the async load unchanged. Wait for later patch to handle it.

@winoros
Copy link
Member Author

winoros commented Apr 10, 2024

/retest

@@ -195,11 +195,21 @@ func (c *columnStatsUsageCollector) addHistNeededColumns(ds *DataSource) {
colIDSet := intset.NewFastIntSet()

for _, col := range columns {
// If the column is plan-generated one, Skip it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "plan-generated" mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such that ID=-1 means ExtraHandleCol

tblColID := model.TableItemID{TableID: ds.physicalTableID, ID: col.ID, IsIndex: false}
colIDSet.Insert(int(col.ID))
c.histNeededCols[tblColID] = true
}
for _, col := range ds.Columns {
// If the column is plan-generated one, Skip it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

pkg/statistics/table.go Outdated Show resolved Hide resolved
// If we don't have it in memory, we create a fake hist for pseudo estimation.
if !ok {
// If we don't have this column. We skip it.
// It's something ridiculous. But it's possible that the stats don't have some ColumnInfo.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means this column has stats but doesn't have ColumnInfo.
In what case would this happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such that alter table add column ddl event is not handled by the StatsHandle. Currently, the statistis.Table is initialized by the stats. not by the model.TableInfo

pkg/statistics/table.go Outdated Show resolved Hide resolved
Copy link

ti-chi-bot bot commented Apr 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, time-and-fate

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the lgtm label Apr 11, 2024
@time-and-fate
Copy link
Member

/hold

Copy link

ti-chi-bot bot commented Apr 11, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-04-11 01:27:47.487924435 +0000 UTC m=+1098529.015464976: ☑️ agreed by hawkingrei.
  • 2024-04-11 15:00:35.165426847 +0000 UTC m=+1147296.692967394: ☑️ agreed by time-and-fate.

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 11, 2024
Co-authored-by: Zhou Kunqin <25057648+time-and-fate@users.noreply.github.com>
@ti-chi-bot ti-chi-bot bot added the sig/planner SIG: Planner label Apr 15, 2024
@winoros
Copy link
Member Author

winoros commented Apr 15, 2024

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 15, 2024
@ti-chi-bot ti-chi-bot bot merged commit 7a85b01 into pingcap:master Apr 15, 2024
12 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #52614.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-8.1 release-note-none sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent row count estimation between lite stats init and non-lite init when table has no stats
4 participants