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

Unexpected Result by REGEXP #49107

Open
bajinsheng opened this issue Dec 2, 2023 · 4 comments
Open

Unexpected Result by REGEXP #49107

bajinsheng opened this issue Dec 2, 2023 · 4 comments
Assignees
Labels
fuzz/sqlancer sig/planner SIG: Planner type/bug This issue is a bug.

Comments

@bajinsheng
Copy link

Bug Report

I believe this is a bug as two queries return inconsistent results.
Although the view includes a GROUP BY, it does not break the only_full_group_by attribute.

1. Minimal reproduce step (Required)

CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT);
INSERT INTO t0 VALUES (1), (2);
INSERT INTO t1 VALUES (3);
CREATE VIEW v0(c0, c1) AS SELECT t0.c0, (false NOT REGEXP t1.c0) LIKE 0 FROM t1, t0 GROUP BY t1.c0;

SELECT v0.c0 FROM v0; -- {2}
SELECT v0.c0 FROM v0 WHERE NOT v0.c1; -- {1}

2. What did you expect to see? (Required)

The first query should return 2 rows because the second query returns a different result.

3. What did you see instead (Required)

The second query returns a different result as that of the first query.

4. What is your TiDB version? (Required)

| Release Version: v7.6.0-alpha-347-g598ccada40-dirty
Edition: Community
Git Commit Hash: 598ccada4065e4871bc5bce53a039cbb598a6d82
Git Branch: master
UTC Build Time: 2023-12-01 01:44:42
GoVersion: go1.21.0
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
@bajinsheng bajinsheng added the type/bug This issue is a bug. label Dec 2, 2023
@bajinsheng
Copy link
Author

/label fuzz/sqlancer

@seiya-annie seiya-annie added the sig/execution SIG execution label Dec 5, 2023
@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 5, 2023

tidb:4003 [test]> select c0 from v0;
+------+
| c0   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

tidb:4003 [test]> desc select c0 from v0;
+-------------------------------+---------+-----------+---------------+-------------------------------------------------------------+
| id                            | estRows | task      | access object | operator info                                               |
+-------------------------------+---------+-----------+---------------+-------------------------------------------------------------+
| HashAgg_10                    | 1.00    | root      |               | group by:test.t1.c0, funcs:firstrow(test.t0.c0)->test.t0.c0 |
| └─HashJoin_12                 | 2.00    | root      |               | CARTESIAN inner join                                        |
|   ├─TableReader_14(Build)     | 1.00    | root      |               | data:TableFullScan_13                                       |
|   │ └─TableFullScan_13        | 1.00    | cop[tikv] | table:t1      | keep order:false, stats:pseudo                              |
|   └─TableReader_16(Probe)     | 2.00    | root      |               | data:TableFullScan_15                                       |
|     └─TableFullScan_15        | 2.00    | cop[tikv] | table:t0      | keep order:false, stats:pseudo                              |
+-------------------------------+---------+-----------+---------------+-------------------------------------------------------------+
6 rows in set (0.00 sec)

tidb:4003 [test]> drop stats t0, t1;
Query OK, 0 rows affected (0.01 sec)

tidb:4003 [test]> select c0 from v0;
+------+
| c0   |
+------+
|    2 |
+------+
1 row in set (0.00 sec)

tidb:4003 [test]> desc select c0 from v0;
+-------------------------------+--------------+-----------+---------------+-------------------------------------------------------------+
| id                            | estRows      | task      | access object | operator info                                               |
+-------------------------------+--------------+-----------+---------------+-------------------------------------------------------------+
| HashAgg_10                    | 8000.00      | root      |               | group by:test.t1.c0, funcs:firstrow(test.t0.c0)->test.t0.c0 |
| └─HashJoin_11                 | 100000000.00 | root      |               | CARTESIAN inner join                                        |
|   ├─TableReader_16(Build)     | 10000.00     | root      |               | data:TableFullScan_15                                       |
|   │ └─TableFullScan_15        | 10000.00     | cop[tikv] | table:t0      | keep order:false, stats:pseudo                              |
|   └─TableReader_14(Probe)     | 10000.00     | root      |               | data:TableFullScan_13                                       |
|     └─TableFullScan_13        | 10000.00     | cop[tikv] | table:t1      | keep order:false, stats:pseudo                              |
+-------------------------------+--------------+-----------+---------------+-------------------------------------------------------------+
6 rows in set (0.00 sec)

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 5, 2023

mysql> SELECT t0.c0, (false NOT REGEXP t1.c0) LIKE 0 FROM t1, t0 GROUP BY t1.c0;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t0.c0' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

The definition of view breaks only_full_group_by.

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 5, 2023

MySQL can raise the error when querying from the view, but tidb does not.
It would be a bug related to planner.

mysql> SELECT v0.c0 FROM v0; -- {2}
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t0.c0' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql> SELECT v0.c0 FROM v0 WHERE NOT v0.c1; -- {1}
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t0.c0' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql> SELECT t0.c0, (false NOT REGEXP t1.c0) LIKE 0 FROM t1, t0 GROUP BY t1.c0;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t0.c0' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

@XuHuaiyu XuHuaiyu added sig/planner SIG: Planner and removed sig/execution SIG execution labels Dec 5, 2023
@hawkingrei hawkingrei self-assigned this Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzz/sqlancer sig/planner SIG: Planner type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants