Skip to content

Commit

Permalink
Added more index scan and pk tests and fixed more bugs in the process
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Jun 23, 2022
1 parent a642d65 commit 678e677
Show file tree
Hide file tree
Showing 8 changed files with 1,978 additions and 195 deletions.
2 changes: 1 addition & 1 deletion parplan/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func schemaToInfoSchema(schema *common.Schema) infoschema.InfoSchema {
FieldType: *colType,
ID: int64(columnIndex + 1),
}
for pkIndex := range tableInfo.PrimaryKeyCols {
for _, pkIndex := range tableInfo.PrimaryKeyCols {
if columnIndex == pkIndex {
col.Flag |= mysql.PriKeyFlag
break
Expand Down
18 changes: 14 additions & 4 deletions pull/exec/index_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func NewPullIndexReader(tableInfo *common.TableInfo, //nolint:gocyclo
for i, colIndex := range colIndexes {
colIndexesMap[colIndex] = i
}
// And the PK cols
pkSet := make(map[int]struct{}, len(tableInfo.PrimaryKeyCols))
for _, pkCol := range tableInfo.PrimaryKeyCols {
pkSet[pkCol] = struct{}{}
}
var indexOutputCols, pkOutputCols []int
var indexColTypes, pkColTypes []common.ColumnType
var includedCols []bool
Expand All @@ -57,11 +62,16 @@ func NewPullIndexReader(tableInfo *common.TableInfo, //nolint:gocyclo
for i, indexCol := range indexInfo.IndexCols {
position, ok := colIndexesMap[indexCol]
if ok {
// The index col is in the output
indexOutputCols[i] = position
} else {
indexOutputCols[i] = -1
// We only count the index col if it's on a PK col. The PK cols will be added in pkOutputCols
// and we don't want to add a column both in indexOutputCols and pkOutputCols
_, ok := pkSet[indexCol]
if !ok {
// The index col is in the output
indexOutputCols[i] = position
continue
}
}
indexOutputCols[i] = -1
}

indexColTypes = make([]common.ColumnType, len(indexInfo.IndexCols))
Expand Down
140 changes: 139 additions & 1 deletion sqltest/testdata/index_scan_test_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,142 @@ dataset:dataset_10 test_source_1
1,2020-01-01 01:00:00.123456
2,2021-02-13 21:11:07.645465
3,2001-11-27 21:34:25.575656
4,1991-06-11 14:34:12.575656
4,1991-06-11 14:34:12.575656
dataset:dataset_11 test_source_1
10,100,1000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo000
10,100,1000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo001
10,100,1000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo002
10,100,1000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo003
10,100,1000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo004
10,100,1000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo005
10,100,1000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo006
10,100,1000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo007
10,100,1000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo008
10,100,1000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo009
10,100,1000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo010
10,100,1000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo011
10,100,1000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo012
10,100,1000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo013
10,100,1000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo014
10,100,1000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo015
10,100,6000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo016
10,100,6000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo017
10,100,6000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo018
10,100,6000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo019
10,100,6000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo020
10,100,6000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo021
10,100,6000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo022
10,100,6000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo023
10,100,6000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo024
10,100,6000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo025
10,100,6000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo026
10,100,6000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo027
10,100,6000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo028
10,100,6000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo029
10,100,6000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo030
10,100,6000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo031
10,500,1000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo032
10,500,1000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo033
10,500,1000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo034
10,500,1000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo035
10,500,1000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo036
10,500,1000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo037
10,500,1000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo038
10,500,1000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo039
10,500,1000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo040
10,500,1000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo041
10,500,1000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo042
10,500,1000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo043
10,500,1000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo044
10,500,1000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo045
10,500,1000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo046
10,500,1000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo047
10,500,6000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo048
10,500,6000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo049
10,500,6000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo050
10,500,6000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo051
10,500,6000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo052
10,500,6000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo053
10,500,6000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo054
10,500,6000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo055
10,500,6000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo056
10,500,6000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo057
10,500,6000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo058
10,500,6000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo059
10,500,6000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo060
10,500,6000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo061
10,500,6000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo062
10,500,6000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo063
20,100,1000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo064
20,100,1000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo065
20,100,1000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo066
20,100,1000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo067
20,100,1000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo068
20,100,1000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo069
20,100,1000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo070
20,100,1000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo071
20,100,1000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo072
20,100,1000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo073
20,100,1000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo074
20,100,1000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo075
20,100,1000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo076
20,100,1000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo077
20,100,1000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo078
20,100,1000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo079
20,100,6000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo080
20,100,6000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo081
20,100,6000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo082
20,100,6000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo083
20,100,6000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo084
20,100,6000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo085
20,100,6000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo086
20,100,6000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo087
20,100,6000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo088
20,100,6000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo089
20,100,6000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo090
20,100,6000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo091
20,100,6000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo092
20,100,6000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo093
20,100,6000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo094
20,100,6000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo095
20,500,1000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo096
20,500,1000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo097
20,500,1000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo098
20,500,1000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo099
20,500,1000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo100
20,500,1000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo101
20,500,1000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo102
20,500,1000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo103
20,500,1000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo104
20,500,1000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo105
20,500,1000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo106
20,500,1000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo107
20,500,1000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo108
20,500,1000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo109
20,500,1000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo110
20,500,1000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo111
20,500,6000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo112
20,500,6000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo113
20,500,6000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo114
20,500,6000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo115
20,500,6000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo116
20,500,6000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo117
20,500,6000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo118
20,500,6000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo119
20,500,6000,8234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo120
20,500,6000,8234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo121
20,500,6000,8234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo122
20,500,6000,8234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo123
20,500,6000,8234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo124
20,500,6000,8234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo125
20,500,6000,8234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo126
20,500,6000,8234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo127
dataset:dataset_12 test_source_1
10,100,1000,1234.4321,12345678.99,str1,2020-01-01 01:00:00.123456,foo000,0
10,100,1000,1234.4321,12345678.99,str1,2021-02-13 21:11:07.645465,foo000,1
10,100,1000,1234.4321,12345678.99,str2,2020-01-01 01:00:00.123456,foo001,0
10,100,1000,1234.4321,12345678.99,str2,2021-02-13 21:11:07.645465,foo001,1
20,100,1000,1234.4321,72345678.99,str1,2020-01-01 01:00:00.123456,foo002,0
20,100,1000,1234.4321,72345678.99,str1,2021-02-13 21:11:07.645465,foo002,1
20,100,1000,1234.4321,72345678.99,str2,2020-01-01 01:00:00.123456,foo003,0
20,100,1000,1234.4321,72345678.99,str2,2021-02-13 21:11:07.645465,foo003,1
Loading

0 comments on commit 678e677

Please sign in to comment.