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: fix wrong row-sizes used in cost model #33845

Merged
merged 25 commits into from
Apr 13, 2022

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Apr 10, 2022

What problem does this PR solve?

Issue Number: close #33844

Problem Summary: planner: fix wrong row-sizes used in cost model

What is changed and how it works?

Please see #33844 for more details.

After this PR, when using and calculating row-size, we should follow the rule below:

for table/index for scan/net function used to calculate row-size
table scan GetTableAvgRowSize
index scan indexScanRowSize
* net GetAvgRowSize

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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

@qw4990 qw4990 added type/bugfix This PR fixes a bug. sig/planner SIG: Planner labels Apr 10, 2022
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 10, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • time-and-fate
  • xuyifangreeneyes

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 10, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Apr 10, 2022

@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 10, 2022
@ti-chi-bot ti-chi-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 10, 2022
@qw4990 qw4990 changed the title planner: fix wrong row-sizes used in cost model (WIP) planner: fix wrong row-sizes used in cost model Apr 11, 2022
@qw4990
Copy link
Contributor Author

qw4990 commented Apr 11, 2022

/bench +tpch

@qw4990 qw4990 requested review from winoros and time-and-fate April 11, 2022 02:38
Comment on lines -257 to +268
└─HashJoin 91515927.49 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)]
└─IndexHashJoin 91515927.49 root inner join, inner:IndexLookUp, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)
├─HashJoin(Build) 22592975.51 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)]
│ ├─TableReader(Build) 1498236.00 root data:Selection
│ │ └─Selection 1498236.00 cop[tikv] eq(tpch.customer.c_mktsegment, "AUTOMOBILE")
│ │ └─TableFullScan 7500000.00 cop[tikv] table:customer keep order:false
│ └─TableReader(Probe) 36870000.00 root data:Selection
│ └─Selection 36870000.00 cop[tikv] lt(tpch.orders.o_orderdate, 1995-03-13 00:00:00.000000)
│ └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false
└─TableReader(Probe) 163047704.27 root data:Selection
└─Selection 163047704.27 cop[tikv] gt(tpch.lineitem.l_shipdate, 1995-03-13 00:00:00.000000)
└─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false
└─IndexLookUp(Probe) 4.05 root
├─IndexRangeScan(Build) 7.45 cop[tikv] table:lineitem, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)], keep order:false
└─Selection(Probe) 4.05 cop[tikv] gt(tpch.lineitem.l_shipdate, 1995-03-13 00:00:00.000000)
└─TableRowIDScan 7.45 cop[tikv] table:lineitem keep order:false
Copy link
Contributor Author

@qw4990 qw4990 Apr 11, 2022

Choose a reason for hiding this comment

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

I ran our TPCH bench again and this plan change won't cause regression:
image

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 12, 2022
@@ -959,6 +959,8 @@ func (p *LogicalJoin) constructInnerTableScanTask(
isPartition: ds.isPartition,

underInnerIndexJoin: true,
tblCols: ds.TblCols,
tblColHists: ds.TblColHists,
Copy link
Contributor

Choose a reason for hiding this comment

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

We use ts.StoreType but we don't explicitly set it(just implicitly set it to TiKV). Do we need to improve it in the future?

Copy link
Contributor Author

@qw4990 qw4990 Apr 13, 2022

Choose a reason for hiding this comment

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

Actually no need to set it explicitly here since IndexLookJoin is only for TiKV, but I think you are right, it's better to set it explicitly here to make it clearer, and I'll fix it in the next PR.

is, partialCost, rowCount := ds.getOriginalPhysicalIndexScan(prop, path, false, false)
rowSize := is.indexScanRowSize(idx, ds, false)
rowSize := is.stats.HistColl.GetAvgRowSize(is.ctx, is.schema.Columns, true, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we change the actual logic here? In indexScanRowSize we check whether to add handleCol before calculating rowSize.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a small logical change, but I think this change is acceptable since 1) it won't cause plan-regression, 2) I'll further improve it later, 3) the current implementation is too sophisticated to maintain.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 13, 2022
@qw4990
Copy link
Contributor Author

qw4990 commented Apr 13, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 98d8772

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 13, 2022
@ti-chi-bot ti-chi-bot merged commit f5c2710 into pingcap:master Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner: the function used to calculate row size in some places is not correct
5 participants