-
Notifications
You must be signed in to change notification settings - Fork 6k
expression: simple expression IsTruthWithNull/IsTruthWithoutNull with CAST #61076
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
Open
hawkingrei
wants to merge
6
commits into
pingcap:master
Choose a base branch
from
hawkingrei:61062
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a48ce5a
planner: fix incorrect query result may caused by join
hawkingrei d048d40
executor: simple expression IsTruthWithNull/IsTruthWithNull with CAST
hawkingrei 5539919
executor: simple expression IsTruthWithNull/IsTruthWithNull with CAST
hawkingrei c6d2944
update
hawkingrei 8ec7e0c
update
hawkingrei 3dc6f01
update
hawkingrei 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_test") | ||
|
||
go_test( | ||
name = "simplify_test", | ||
timeout = "short", | ||
srcs = [ | ||
"main_test.go", | ||
"simplify_test.go", | ||
], | ||
flaky = True, | ||
deps = [ | ||
"//pkg/config", | ||
"//pkg/testkit", | ||
"//pkg/testkit/testmain", | ||
"//pkg/testkit/testsetup", | ||
"//pkg/util/timeutil", | ||
"@com_github_tikv_client_go_v2//tikv", | ||
"@org_uber_go_goleak//:goleak", | ||
], | ||
) |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2025 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package simplify | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/pkg/config" | ||
"github.com/pingcap/tidb/pkg/testkit/testmain" | ||
"github.com/pingcap/tidb/pkg/testkit/testsetup" | ||
"github.com/pingcap/tidb/pkg/util/timeutil" | ||
"github.com/tikv/client-go/v2/tikv" | ||
"go.uber.org/goleak" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testsetup.SetupForCommonTest() | ||
testmain.ShortCircuitForBench(m) | ||
|
||
config.UpdateGlobal(func(conf *config.Config) { | ||
conf.TiKVClient.AsyncCommit.SafeWindow = 0 | ||
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 | ||
conf.Experimental.AllowsExpressionIndex = true | ||
}) | ||
tikv.EnableFailpoints() | ||
|
||
// Some test depends on the values of timeutil.SystemLocation() | ||
// If we don't SetSystemTZ() here, the value would change unpredictable. | ||
// Affected by the order whether a testsuite runs before or after integration test. | ||
// Note, SetSystemTZ() is a sync.Once operation. | ||
timeutil.SetSystemTZ("system") | ||
|
||
opts := []goleak.Option{ | ||
goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"), | ||
goleak.IgnoreTopFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"), | ||
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"), | ||
goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"), | ||
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), | ||
goleak.IgnoreTopFunction("github.com/pingcap/tidb/pkg/ttl/ttlworker.(*ttlScanWorker).loop"), | ||
goleak.IgnoreTopFunction("github.com/pingcap/tidb/pkg/ttl/client.(*mockClient).WatchCommand.func1"), | ||
goleak.IgnoreTopFunction("github.com/pingcap/tidb/pkg/ttl/ttlworker.(*JobManager).jobLoop"), | ||
} | ||
|
||
goleak.VerifyTestMain(m, opts...) | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2025 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package simplify | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/pkg/testkit" | ||
) | ||
|
||
func TestIsTruthXXXWithCast(t *testing.T) { | ||
store := testkit.CreateMockStore(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test;") | ||
// https://github.com/pingcap/tidb/issues/61062 | ||
tk.MustExec(`CREATE TABLE t0(c0 FLOAT UNSIGNED);`) | ||
tk.MustExec(`CREATE TABLE t1 LIKE t0;`) | ||
tk.MustExec(`INSERT IGNORE INTO t0 VALUES (0.5);`) | ||
tk.MustExec(`INSERT IGNORE INTO t1 VALUES (NULL);`) | ||
tk.MustQuery(`SELECT t0.c0, t1.c0 FROM t0 INNER JOIN t1 ON true WHERE (NOT (CAST(t0.c0 AS DATETIME)));`). | ||
Check(testkit.Rows()) | ||
tk.MustQuery(`explain format=brief SELECT t0.c0, t1.c0 FROM t0 INNER JOIN t1 ON true WHERE (NOT (CAST(t0.c0 AS DATETIME)));`). | ||
Check(testkit.Rows("HashJoin 100000.00 root CARTESIAN inner join", | ||
"├─TableReader(Build) 10.00 root data:Selection", | ||
"│ └─Selection 10.00 cop[tikv] not(istrue_with_null(test.t0.c0))", | ||
"│ └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo", | ||
"└─TableReader(Probe) 10000.00 root data:TableFullScan", | ||
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) | ||
tk.MustQuery(`SELECT t0.c0, t1.c0 FROM t0 LEFT JOIN t1 ON true WHERE (NOT (CAST(t0.c0 AS DATETIME))) | ||
INTERSECT | ||
SELECT t0.c0, t1.c0 FROM t0 RIGHT JOIN t1 ON true WHERE (NOT (CAST(t0.c0 AS DATETIME)));`).Check(testkit.Rows()) | ||
tk.MustQuery(`explain format=brief SELECT t0.c0, t1.c0 FROM t0 LEFT JOIN t1 ON true WHERE (NOT (CAST(t0.c0 AS DATETIME))) | ||
INTERSECT | ||
SELECT t0.c0, t1.c0 FROM t0 RIGHT JOIN t1 ON true WHERE (NOT (CAST(t0.c0 AS DATETIME)));`).Check(testkit.Rows( | ||
"HashJoin 6400.00 root semi join, left side:HashAgg, equal:[nulleq(test.t0.c0, test.t0.c0) nulleq(test.t1.c0, test.t1.c0)]", | ||
"├─HashJoin(Build) 100000.00 root CARTESIAN inner join", | ||
"│ ├─TableReader(Build) 10.00 root data:Selection", | ||
"│ │ └─Selection 10.00 cop[tikv] not(istrue_with_null(test.t0.c0))", | ||
"│ │ └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo", | ||
"│ └─TableReader(Probe) 10000.00 root data:TableFullScan", | ||
"│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", | ||
"└─HashAgg(Probe) 8000.00 root group by:test.t0.c0, test.t1.c0, funcs:firstrow(test.t0.c0)->test.t0.c0, funcs:firstrow(test.t1.c0)->test.t1.c0", | ||
" └─HashJoin 100000.00 root CARTESIAN left outer join, left side:TableReader", | ||
" ├─TableReader(Build) 10.00 root data:Selection", | ||
" │ └─Selection 10.00 cop[tikv] not(istrue_with_null(test.t0.c0))", | ||
" │ └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo", | ||
" └─TableReader(Probe) 10000.00 root data:TableFullScan", | ||
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) | ||
// https://github.com/pingcap/tidb/issues/51359 | ||
tk.MustExec("DROP TABLE t0;") | ||
tk.MustExec("CREATE TABLE t0(c0 BOOL);") | ||
tk.MustExec("REPLACE INTO t0(c0) VALUES (false), (true);") | ||
tk.MustExec("CREATE VIEW v0(c0) AS SELECT (REGEXP_LIKE(t0.c0, t0.c0)) FROM t0 WHERE t0.c0 GROUP BY t0.c0 HAVING 1;") | ||
tk.MustQuery(`SELECT t0.c0 FROM v0, t0 WHERE (SUBTIME('2001-11-28 06', '252 10') OR ('' IS NOT NULL));`).Check(testkit.Rows("0", "1")) | ||
tk.MustQuery(`explain format='brief' SELECT t0.c0 FROM v0, t0 WHERE (SUBTIME('2001-11-28 06', '252 10') OR ('' IS NOT NULL));`).Check(testkit.Rows( | ||
"HashJoin 27265706.67 root CARTESIAN inner join", | ||
"├─Selection(Build) 3408.21 root or(istrue_with_null(cast(subtime(\"2001-11-28 06\", \"252 10\"), double BINARY)), 1)", | ||
"│ └─HashAgg 4260.27 root group by:test.t0.c0, funcs:firstrow(1)->Column#7", | ||
"│ └─Selection 5325.33 root or(istrue_with_null(cast(subtime(\"2001-11-28 06\", \"252 10\"), double BINARY)), 1)", | ||
"│ └─TableReader 6656.67 root data:Selection", | ||
"│ └─Selection 6656.67 cop[tikv] test.t0.c0", | ||
"│ └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo", | ||
"└─Selection(Probe) 8000.00 root or(istrue_with_null(cast(subtime(\"2001-11-28 06\", \"252 10\"), double BINARY)), 1)", | ||
" └─TableReader 10000.00 root data:TableFullScan", | ||
" └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo")) | ||
tk.MustQuery(`SELECT t0.c0 FROM v0, t0 WHERE (SUBTIME('2001-11-28 06', '252 10') OR ('' IS NOT NULL)) AND v0.c0;`). | ||
Check(testkit.Rows("0", "1")) | ||
tk.MustQuery(`explain format='brief' SELECT t0.c0 FROM v0, t0 WHERE (SUBTIME('2001-11-28 06', '252 10') OR ('' IS NOT NULL)) AND v0.c0;`). | ||
Check(testkit.Rows( | ||
"HashJoin 27265706.67 root CARTESIAN inner join", | ||
"├─Selection(Build) 3408.21 root or(istrue_with_null(cast(subtime(\"2001-11-28 06\", \"252 10\"), double BINARY)), 1)", | ||
"│ └─HashAgg 4260.27 root group by:test.t0.c0, funcs:firstrow(Column#9)->Column#8", | ||
"│ └─TableReader 4260.27 root data:HashAgg", | ||
"│ └─HashAgg 4260.27 cop[tikv] group by:test.t0.c0, funcs:firstrow(1)->Column#9", | ||
"│ └─Selection 5325.33 cop[tikv] regexp_like(cast(test.t0.c0, var_string(20)), cast(test.t0.c0, var_string(20))), test.t0.c0", | ||
"│ └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo", | ||
"└─Selection(Probe) 8000.00 root or(istrue_with_null(cast(subtime(\"2001-11-28 06\", \"252 10\"), double BINARY)), 1)", | ||
" └─TableReader 10000.00 root data:TableFullScan", | ||
" └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo")) | ||
} |
This file contains hidden or 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 hidden or 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
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.
The convert is too aggressive, istrue(cast(xxx as xxx)) is not always equal to istrue(xxx)
For example: