@@ -36,6 +36,7 @@ import (
36
36
"github.com/pingcap/tidb/pkg/statistics"
37
37
"github.com/pingcap/tidb/pkg/table"
38
38
"github.com/pingcap/tidb/pkg/types"
39
+ "github.com/pingcap/tidb/pkg/util/intset"
39
40
"github.com/pingcap/tidb/pkg/util/logutil"
40
41
"github.com/pingcap/tidb/pkg/util/ranger"
41
42
"github.com/pingcap/tidb/pkg/util/size"
@@ -298,7 +299,7 @@ func (p *LogicalJoin) extractFDForOuterJoin(filtersFromApply []expression.Expres
298
299
outerFD , innerFD := p .children [0 ].ExtractFD (), p .children [1 ].ExtractFD ()
299
300
innerCondition := p .RightConditions
300
301
outerCondition := p .LeftConditions
301
- outerCols , innerCols := fd .NewFastIntSet (), fd .NewFastIntSet ()
302
+ outerCols , innerCols := intset .NewFastIntSet (), intset .NewFastIntSet ()
302
303
for _ , col := range p .children [0 ].Schema ().Columns {
303
304
outerCols .Insert (int (col .UniqueID ))
304
305
}
@@ -326,7 +327,7 @@ func (p *LogicalJoin) extractFDForOuterJoin(filtersFromApply []expression.Expres
326
327
equivUniqueIDs := extractEquivalenceCols (allConds , p .SCtx (), filterFD )
327
328
328
329
filterFD .AddConstants (constUniqueIDs )
329
- equivOuterUniqueIDs := fd .NewFastIntSet ()
330
+ equivOuterUniqueIDs := intset .NewFastIntSet ()
330
331
equivAcrossNum := 0
331
332
for _ , equiv := range equivUniqueIDs {
332
333
filterFD .AddEquivalence (equiv [0 ], equiv [1 ])
@@ -354,7 +355,7 @@ func (p *LogicalJoin) extractFDForOuterJoin(filtersFromApply []expression.Expres
354
355
// other condition may contain right side cols, it doesn't affect the judgement of intersection of non-left-equiv cols.
355
356
outConditionCols = append (outConditionCols , expression .ExtractColumnsFromExpressions (nil , p .OtherConditions , nil )... )
356
357
}
357
- outerConditionUniqueIDs := fd .NewFastIntSet ()
358
+ outerConditionUniqueIDs := intset .NewFastIntSet ()
358
359
for _ , col := range outConditionCols {
359
360
outerConditionUniqueIDs .Insert (int (col .UniqueID ))
360
361
}
@@ -857,8 +858,8 @@ func (p *LogicalProjection) ExtractFD() *fd.FDSet {
857
858
// basically extract the children's fdSet.
858
859
fds := p .logicalSchemaProducer .ExtractFD ()
859
860
// collect the output columns' unique ID.
860
- outputColsUniqueIDs := fd .NewFastIntSet ()
861
- notnullColsUniqueIDs := fd .NewFastIntSet ()
861
+ outputColsUniqueIDs := intset .NewFastIntSet ()
862
+ notnullColsUniqueIDs := intset .NewFastIntSet ()
862
863
outputColsUniqueIDsArray := make ([]int , 0 , len (p .Schema ().Columns ))
863
864
// here schema extended columns may contain expr, const and column allocated with uniqueID.
864
865
for _ , one := range p .Schema ().Columns {
@@ -885,7 +886,7 @@ func (p *LogicalProjection) ExtractFD() *fd.FDSet {
885
886
constantUniqueID = outputColsUniqueIDsArray [idx ]
886
887
fds .RegisterUniqueID (string (x .HashCode (p .SCtx ().GetSessionVars ().StmtCtx )), constantUniqueID )
887
888
}
888
- fds .AddConstants (fd .NewFastIntSet (constantUniqueID ))
889
+ fds .AddConstants (intset .NewFastIntSet (constantUniqueID ))
889
890
case * expression.ScalarFunction :
890
891
// t1(a,b,c), t2(m,n)
891
892
// select a, (select c+n from t2 where m=b) from t1;
@@ -908,9 +909,9 @@ func (p *LogicalProjection) ExtractFD() *fd.FDSet {
908
909
} else {
909
910
// since the scalar's hash code has been registered before, the equivalence exists between the unique ID
910
911
// allocated by phase of building-projection-for-scalar and that of previous registered unique ID.
911
- fds .AddEquivalence (fd .NewFastIntSet (scalarUniqueID ), fd .NewFastIntSet (outputColsUniqueIDsArray [idx ]))
912
+ fds .AddEquivalence (intset .NewFastIntSet (scalarUniqueID ), intset .NewFastIntSet (outputColsUniqueIDsArray [idx ]))
912
913
}
913
- determinants := fd .NewFastIntSet ()
914
+ determinants := intset .NewFastIntSet ()
914
915
extractedColumns := expression .ExtractColumns (x )
915
916
extractedCorColumns := expression .ExtractCorColumns (x )
916
917
for _ , one := range extractedColumns {
@@ -927,7 +928,7 @@ func (p *LogicalProjection) ExtractFD() *fd.FDSet {
927
928
if notnull || determinants .SubsetOf (fds .NotNullCols ) {
928
929
notnullColsUniqueIDs .Insert (scalarUniqueID )
929
930
}
930
- fds .AddStrictFunctionalDependency (determinants , fd .NewFastIntSet (scalarUniqueID ))
931
+ fds .AddStrictFunctionalDependency (determinants , intset .NewFastIntSet (scalarUniqueID ))
931
932
}
932
933
}
933
934
@@ -1013,10 +1014,10 @@ func (la *LogicalAggregation) ExtractFD() *fd.FDSet {
1013
1014
// basically extract the children's fdSet.
1014
1015
fds := la .logicalSchemaProducer .ExtractFD ()
1015
1016
// collect the output columns' unique ID.
1016
- outputColsUniqueIDs := fd .NewFastIntSet ()
1017
- notnullColsUniqueIDs := fd .NewFastIntSet ()
1018
- groupByColsUniqueIDs := fd .NewFastIntSet ()
1019
- groupByColsOutputCols := fd .NewFastIntSet ()
1017
+ outputColsUniqueIDs := intset .NewFastIntSet ()
1018
+ notnullColsUniqueIDs := intset .NewFastIntSet ()
1019
+ groupByColsUniqueIDs := intset .NewFastIntSet ()
1020
+ groupByColsOutputCols := intset .NewFastIntSet ()
1020
1021
// Since the aggregation is build ahead of projection, the latter one will reuse the column with UniqueID allocated in aggregation
1021
1022
// via aggMapper, so we don't need unnecessarily maintain the <aggDes, UniqueID> mapping in the FDSet like expr did, just treating
1022
1023
// it as normal column.
@@ -1051,7 +1052,7 @@ func (la *LogicalAggregation) ExtractFD() *fd.FDSet {
1051
1052
fds .RegisterUniqueID (hashCode , scalarUniqueID )
1052
1053
groupByColsUniqueIDs .Insert (scalarUniqueID )
1053
1054
}
1054
- determinants := fd .NewFastIntSet ()
1055
+ determinants := intset .NewFastIntSet ()
1055
1056
extractedColumns := expression .ExtractColumns (x )
1056
1057
extractedCorColumns := expression .ExtractCorColumns (x )
1057
1058
for _ , one := range extractedColumns {
@@ -1066,7 +1067,7 @@ func (la *LogicalAggregation) ExtractFD() *fd.FDSet {
1066
1067
if notnull || determinants .SubsetOf (fds .NotNullCols ) {
1067
1068
notnullColsUniqueIDs .Insert (scalarUniqueID )
1068
1069
}
1069
- fds .AddStrictFunctionalDependency (determinants , fd .NewFastIntSet (scalarUniqueID ))
1070
+ fds .AddStrictFunctionalDependency (determinants , intset .NewFastIntSet (scalarUniqueID ))
1070
1071
}
1071
1072
}
1072
1073
@@ -1078,7 +1079,7 @@ func (la *LogicalAggregation) ExtractFD() *fd.FDSet {
1078
1079
//
1079
1080
// and since any_value will NOT be pushed down to agg schema, which means every firstRow aggDes in the agg logical operator
1080
1081
// is meaningless to build the FD with. Let's only store the non-firstRow FD down: {group by items} ~~> {real aggDes}
1081
- realAggFuncUniqueID := fd .NewFastIntSet ()
1082
+ realAggFuncUniqueID := intset .NewFastIntSet ()
1082
1083
for i , aggDes := range la .AggFuncs {
1083
1084
if aggDes .Name != "firstrow" {
1084
1085
realAggFuncUniqueID .Insert (int (la .schema .Columns [i ].UniqueID ))
@@ -1095,7 +1096,7 @@ func (la *LogicalAggregation) ExtractFD() *fd.FDSet {
1095
1096
// 0 unique id is only used for here.
1096
1097
groupByColsUniqueIDs .Insert (0 )
1097
1098
for i , ok := realAggFuncUniqueID .Next (0 ); ok ; i , ok = realAggFuncUniqueID .Next (i + 1 ) {
1098
- fds .AddStrictFunctionalDependency (groupByColsUniqueIDs , fd .NewFastIntSet (i ))
1099
+ fds .AddStrictFunctionalDependency (groupByColsUniqueIDs , intset .NewFastIntSet (i ))
1099
1100
}
1100
1101
} else {
1101
1102
// eliminating input columns that are un-projected.
@@ -1107,7 +1108,7 @@ func (la *LogicalAggregation) ExtractFD() *fd.FDSet {
1107
1108
// 1: it can always distinguish and group the all-null/part-null group column rows.
1108
1109
// 2: the rows with all/part null group column are unique row after group operation.
1109
1110
// 3: there won't be two same group key with different agg values, so strict FD secured.
1110
- fds .AddStrictFunctionalDependency (groupByColsUniqueIDs , fd .NewFastIntSet (i ))
1111
+ fds .AddStrictFunctionalDependency (groupByColsUniqueIDs , intset .NewFastIntSet (i ))
1111
1112
}
1112
1113
1113
1114
// agg funcDes has been tag not null flag when building aggregation.
@@ -1211,7 +1212,7 @@ type LogicalSelection struct {
1211
1212
Conditions []expression.Expression
1212
1213
}
1213
1214
1214
- func extractNotNullFromConds (conditions []expression.Expression , p LogicalPlan ) fd .FastIntSet {
1215
+ func extractNotNullFromConds (conditions []expression.Expression , p LogicalPlan ) intset .FastIntSet {
1215
1216
// extract the column NOT NULL rejection characteristic from selection condition.
1216
1217
// CNF considered only, DNF doesn't have its meanings (cause that condition's eval may don't take effect)
1217
1218
//
@@ -1224,7 +1225,7 @@ func extractNotNullFromConds(conditions []expression.Expression, p LogicalPlan)
1224
1225
// 2: `b` must be null since only `NULL is NULL` is evaluated as true.
1225
1226
//
1226
1227
// As a result, `a` will be extracted as not-null column to abound the FDSet.
1227
- notnullColsUniqueIDs := fd .NewFastIntSet ()
1228
+ notnullColsUniqueIDs := intset .NewFastIntSet ()
1228
1229
for _ , condition := range conditions {
1229
1230
var cols []* expression.Column
1230
1231
cols = expression .ExtractColumnsFromExpressions (cols , []expression.Expression {condition }, nil )
@@ -1237,13 +1238,13 @@ func extractNotNullFromConds(conditions []expression.Expression, p LogicalPlan)
1237
1238
return notnullColsUniqueIDs
1238
1239
}
1239
1240
1240
- func extractConstantCols (conditions []expression.Expression , sctx sessionctx.Context , fds * fd.FDSet ) fd .FastIntSet {
1241
+ func extractConstantCols (conditions []expression.Expression , sctx sessionctx.Context , fds * fd.FDSet ) intset .FastIntSet {
1241
1242
// extract constant cols
1242
1243
// eg: where a=1 and b is null and (1+c)=5.
1243
1244
// TODO: Some columns can only be determined to be constant from multiple constraints (e.g. x <= 1 AND x >= 1)
1244
1245
var (
1245
1246
constObjs []expression.Expression
1246
- constUniqueIDs = fd .NewFastIntSet ()
1247
+ constUniqueIDs = intset .NewFastIntSet ()
1247
1248
)
1248
1249
constObjs = expression .ExtractConstantEqColumnsOrScalar (sctx , constObjs , conditions )
1249
1250
for _ , constObj := range constObjs {
@@ -1264,10 +1265,10 @@ func extractConstantCols(conditions []expression.Expression, sctx sessionctx.Con
1264
1265
return constUniqueIDs
1265
1266
}
1266
1267
1267
- func extractEquivalenceCols (conditions []expression.Expression , sctx sessionctx.Context , fds * fd.FDSet ) [][]fd .FastIntSet {
1268
+ func extractEquivalenceCols (conditions []expression.Expression , sctx sessionctx.Context , fds * fd.FDSet ) [][]intset .FastIntSet {
1268
1269
var equivObjsPair [][]expression.Expression
1269
1270
equivObjsPair = expression .ExtractEquivalenceColumns (equivObjsPair , conditions )
1270
- equivUniqueIDs := make ([][]fd .FastIntSet , 0 , len (equivObjsPair ))
1271
+ equivUniqueIDs := make ([][]intset .FastIntSet , 0 , len (equivObjsPair ))
1271
1272
for _ , equivObjPair := range equivObjsPair {
1272
1273
// lhs of equivalence.
1273
1274
var (
@@ -1301,7 +1302,7 @@ func extractEquivalenceCols(conditions []expression.Expression, sctx sessionctx.
1301
1302
rhsUniqueID = scalarUniqueID
1302
1303
}
1303
1304
}
1304
- equivUniqueIDs = append (equivUniqueIDs , []fd .FastIntSet {fd .NewFastIntSet (lhsUniqueID ), fd .NewFastIntSet (rhsUniqueID )})
1305
+ equivUniqueIDs = append (equivUniqueIDs , []intset .FastIntSet {intset .NewFastIntSet (lhsUniqueID ), intset .NewFastIntSet (rhsUniqueID )})
1305
1306
}
1306
1307
return equivUniqueIDs
1307
1308
}
@@ -1311,8 +1312,8 @@ func (p *LogicalSelection) ExtractFD() *fd.FDSet {
1311
1312
// basically extract the children's fdSet.
1312
1313
fds := p .baseLogicalPlan .ExtractFD ()
1313
1314
// collect the output columns' unique ID.
1314
- outputColsUniqueIDs := fd .NewFastIntSet ()
1315
- notnullColsUniqueIDs := fd .NewFastIntSet ()
1315
+ outputColsUniqueIDs := intset .NewFastIntSet ()
1316
+ notnullColsUniqueIDs := intset .NewFastIntSet ()
1316
1317
// eg: select t2.a, count(t2.b) from t1 join t2 using (a) where t1.a = 1
1317
1318
// join's schema will miss t2.a while join.full schema has. since selection
1318
1319
// itself doesn't contain schema, extracting schema should tell them apart.
0 commit comments