-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: add an upper bound for estimated row count of inner side of index join #41996
Merged
Merged
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ff50795
add
time-and-fate cb17c50
Merge remote-tracking branch 'upstream/master' into s14-issue31316
time-and-fate 42cfcfb
fmt
time-and-fate 88f933d
update test result
time-and-fate 76a14c9
add test
time-and-fate 54799f2
update test
time-and-fate d099896
Merge remote-tracking branch 'upstream/master' into s14-issue31316
time-and-fate 4b0cd06
reduce changes
time-and-fate 4995403
add comments
time-and-fate c122370
Merge remote-tracking branch 'upstream/master' into s14-issue31316
time-and-fate 6a2ef90
add
time-and-fate 571920f
Merge remote-tracking branch 'upstream/master' into s14-issue31316
time-and-fate dfeabe1
Merge remote-tracking branch 'upstream/master' into s14-issue31316
time-and-fate bf1213e
add
time-and-fate 020b838
Merge remote-tracking branch 'upstream/master' into s14-issue31316
time-and-fate 23f34df
add
time-and-fate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,12 @@ import ( | |
|
||
"github.com/pingcap/failpoint" | ||
"github.com/pingcap/tidb/parser/model" | ||
"github.com/pingcap/tidb/parser/mysql" | ||
"github.com/pingcap/tidb/statistics" | ||
"github.com/pingcap/tidb/statistics/handle" | ||
"github.com/pingcap/tidb/testkit" | ||
"github.com/pingcap/tidb/testkit/testdata" | ||
"github.com/pingcap/tidb/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
|
@@ -693,3 +695,49 @@ func TestSingleColumnIndexNDV(t *testing.T) { | |
require.Equal(t, expectedResults[i][2], row[7]) // null_count | ||
} | ||
} | ||
|
||
func TestIndexJoinInnerRowCountUpperBound(t *testing.T) { | ||
store, dom := testkit.CreateMockStoreAndDomain(t) | ||
testKit := testkit.NewTestKit(t, store) | ||
h := dom.StatsHandle() | ||
|
||
testKit.MustExec("use test") | ||
testKit.MustExec("drop table if exists t") | ||
testKit.MustExec("create table t(a int, b int, index idx(b))") | ||
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh())) | ||
is := dom.InfoSchema() | ||
tb, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) | ||
require.NoError(t, err) | ||
tblInfo := tb.Meta() | ||
|
||
// mock the statistics.Table | ||
mockStatsTbl := mockStatsTable(tblInfo, 500000) | ||
colValues, err := generateIntDatum(1, 500) | ||
require.NoError(t, err) | ||
for i := 1; i <= 2; i++ { | ||
mockStatsTbl.Columns[int64(i)] = &statistics.Column{ | ||
Count: 500000, | ||
Histogram: *mockStatsHistogram(int64(i), colValues, 1000, types.NewFieldType(mysql.TypeLonglong)), | ||
Info: tblInfo.Columns[i-1], | ||
StatsLoadedStatus: statistics.NewStatsFullLoadStatus(), | ||
StatsVer: 2, | ||
} | ||
} | ||
generateMapsForMockStatsTbl(mockStatsTbl) | ||
stat := h.GetTableStats(tblInfo) | ||
stat.HistColl = mockStatsTbl.HistColl | ||
|
||
testKit.MustQuery("explain format = 'brief' " + | ||
"select /*+ inl_join(t2) */ * from (select * from t where t.a < 1) as t1 join t t2 where t2.a = 0 and t1.a = t2.b"). | ||
Check(testkit.Rows( | ||
"IndexJoin 1000000.00 root inner join, inner:IndexLookUp, outer key:test.t.a, inner key:test.t.b, equal cond:eq(test.t.a, test.t.b)", | ||
"├─TableReader(Build) 1000.00 root data:Selection", | ||
"│ └─Selection 1000.00 cop[tikv] lt(test.t.a, 1), not(isnull(test.t.a))", | ||
"│ └─TableFullScan 500000.00 cop[tikv] table:t keep order:false, stats:pseudo", | ||
"└─IndexLookUp(Probe) 1000000.00 root ", | ||
" ├─Selection(Build) 1000000.00 cop[tikv] not(isnull(test.t.b))", | ||
" │ └─IndexRangeScan 1000000.00 cop[tikv] table:t2, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo", | ||
" └─Selection(Probe) 1000000.00 cop[tikv] eq(test.t.a, 0)", | ||
" └─TableRowIDScan 1000000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", | ||
)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a comparison, on current master branch, the execution plan is:
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return max{single col ndv} instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be min.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.