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: address collation ambiguity in scalar function construction during predicate simplification. (#57049) #57476

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/planner/core/rule_predicate_simplification.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ func unsatisfiable(ctx base.PlanContext, p1, p2 expression.Expression) bool {
// Copy constant from equal predicate into other predicate.
equalValue := equalPred.(*expression.ScalarFunction)
otherValue := otherPred.(*expression.ScalarFunction)
newPred := expression.NewFunctionInternal(ctx.GetExprCtx(), otherValue.FuncName.L, otherValue.RetType, equalValue.GetArgs()[1], otherValue.GetArgs()[1])
newPred, err := expression.NewFunction(ctx.GetExprCtx(), otherValue.FuncName.L, otherValue.RetType, equalValue.GetArgs()[1], otherValue.GetArgs()[1])
if err != nil {
return false
}
newPredList := make([]expression.Expression, 0, 1)
newPredList = append(newPredList, newPred)
newPredList = expression.PropagateConstant(ctx.GetExprCtx(), newPredList)
Expand Down Expand Up @@ -273,7 +276,11 @@ func updateOrPredicate(ctx base.PlanContext, orPredicateList expression.Expressi
} else if emptyFirst && emptySecond {
return &expression.Constant{Value: types.NewIntDatum(0), RetType: types.NewFieldType(mysql.TypeTiny)}
}
return expression.NewFunctionInternal(ctx.GetExprCtx(), ast.LogicOr, v.RetType, firstCondition, secondCondition)
newPred, err := expression.NewFunction(ctx.GetExprCtx(), ast.LogicOr, v.RetType, firstCondition, secondCondition)
if err != nil {
return orPredicateList
}
return newPred
}

// pruneEmptyORBranches applies iteratively updateOrPredicate for each pair of OR predicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,21 @@ NULL NULL 2 2 4 2
show warnings;
Level Code Message
drop table if exists t1, t2, t3, t4;
<<<<<<< HEAD
=======
drop table if exists t0, v0;
drop view if exists v0;
CREATE TABLE t0(c0 INTEGER);
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0 WHERE (CASE t0.c0 WHEN t0.c0 THEN false END );
SELECT t0.c0 FROM v0, t0 WHERE RAND();
c0
drop table if exists tl6e913fb9;
CREATE TABLE `tl6e913fb9` (
`col_36` varchar(175) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'asMF',
KEY `idx_35_5` (`col_36`(1)),
PRIMARY KEY (`col_36`) /*T![clustered_index] NONCLUSTERED */,
KEY `idx_65` (`col_36`(5))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
with cte_192 ( col_1101,col_1102,col_1103,col_1104 ) AS ( select /*+ use_index_merge( tl6e913fb9 ) */ replace( tl6e913fb9.col_36 , tl6e913fb9.col_36 , tl6e913fb9.col_36 ) as r0 , space( 0 ) as r1 , min( distinct tl6e913fb9.col_36 ) as r2 , count( distinct tl6e913fb9.col_36 ) as r3 from tl6e913fb9 where tl6e913fb9.col_36 between 'n92ok$B%W#UU%O' and '()c=KVQ=T%-vzGJ' and tl6e913fb9.col_36 in ( 'T+kf' ,'Lvluod2H' ,'3#Omx@pC^fFkeH' ,'=b$z' ) group by tl6e913fb9.col_36 having tl6e913fb9.col_36 = 'xjV@' or IsNull( tl6e913fb9.col_36 ) ) ( select 1,col_1101,col_1102,col_1103,col_1104 from cte_192 where not( IsNull( cte_192.col_1102 ) ) order by 1,2,3,4,5 limit 72850972 );
1 col_1101 col_1102 col_1103 col_1104
>>>>>>> a9c5201884c (planner: address collation ambiguity in scalar function construction during predicate simplification. (#57049))
20 changes: 20 additions & 0 deletions tests/integrationtest/t/planner/core/issuetest/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,23 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
show warnings;
drop table if exists t1, t2, t3, t4;
<<<<<<< HEAD
=======

# TestIssue56270
drop table if exists t0, v0;
drop view if exists v0;
CREATE TABLE t0(c0 INTEGER);
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0 WHERE (CASE t0.c0 WHEN t0.c0 THEN false END );
SELECT t0.c0 FROM v0, t0 WHERE RAND();

# TestIssue56479
drop table if exists tl6e913fb9;
CREATE TABLE `tl6e913fb9` (
`col_36` varchar(175) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'asMF',
KEY `idx_35_5` (`col_36`(1)),
PRIMARY KEY (`col_36`) /*T![clustered_index] NONCLUSTERED */,
KEY `idx_65` (`col_36`(5))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
with cte_192 ( col_1101,col_1102,col_1103,col_1104 ) AS ( select /*+ use_index_merge( tl6e913fb9 ) */ replace( tl6e913fb9.col_36 , tl6e913fb9.col_36 , tl6e913fb9.col_36 ) as r0 , space( 0 ) as r1 , min( distinct tl6e913fb9.col_36 ) as r2 , count( distinct tl6e913fb9.col_36 ) as r3 from tl6e913fb9 where tl6e913fb9.col_36 between 'n92ok$B%W#UU%O' and '()c=KVQ=T%-vzGJ' and tl6e913fb9.col_36 in ( 'T+kf' ,'Lvluod2H' ,'3#Omx@pC^fFkeH' ,'=b$z' ) group by tl6e913fb9.col_36 having tl6e913fb9.col_36 = 'xjV@' or IsNull( tl6e913fb9.col_36 ) ) ( select 1,col_1101,col_1102,col_1103,col_1104 from cte_192 where not( IsNull( cte_192.col_1102 ) ) order by 1,2,3,4,5 limit 72850972 );
>>>>>>> a9c5201884c (planner: address collation ambiguity in scalar function construction during predicate simplification. (#57049))