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 union result #24323

Open
XuHuaiyu opened this issue Apr 27, 2021 · 6 comments
Open

unexpected union result #24323

XuHuaiyu opened this issue Apr 27, 2021 · 6 comments
Labels
severity/minor sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@XuHuaiyu
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE t1 (a VARCHAR(10), FULLTEXT KEY a (a));
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1),(2);

SELECT * FROM t1 UNION SELECT * FROM t1
  ORDER BY (SELECT a FROM t2 WHERE b = 12);

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

mysql> SELECT * FROM t1 UNION SELECT * FROM t1
    ->   ORDER BY (SELECT a FROM t2 WHERE b = 12);
+------+
| a    |
+------+
| 1    |
| 2    |
+------+
2 rows in set (0.00 sec)

3. What did you see instead (Required)

The result is unstable.

tidb> SELECT * FROM t1 UNION SELECT * FROM t1   ORDER BY (SELECT a FROM t2 WHERE b = 12);
+------+
| a    |
+------+
| 2    |
| 1    |
+------+
2 rows in set (0.00 sec)
tidb> SELECT * FROM t1 UNION SELECT * FROM t1   ORDER BY (SELECT a FROM t2 WHERE b = 12);
+------+
| a    |
+------+
| 1    |
| 2    |
+------+
2 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

7e15333 in master

@XuHuaiyu XuHuaiyu added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner severity/major labels Apr 27, 2021
@winoros
Copy link
Member

winoros commented May 20, 2021

This is a very rare corner case, so move the severity down.

@sylzd
Copy link
Contributor

sylzd commented May 26, 2021

/assign

@sylzd
Copy link
Contributor

sylzd commented May 26, 2021

This is a very rare corner case, so move the severity down.

It can be reproduced by common sql like this:

SELECT * FROM t1 union (select * from t1);

@sylzd
Copy link
Contributor

sylzd commented Jun 4, 2021

concurrency of Hash Aggregation bring on this, should I make it sequential? @XuHuaiyu @winoros
when I set variable like this, it worked.

# >4.0
set global tidb_hashagg_partial_concurrency=1
set global tidb_hashagg_final_concurrency=1
# >=5.0
set global tidb_executor_concurrency=1

@sylzd
Copy link
Contributor

sylzd commented Jul 9, 2021

For this issue, order does not work because field a not exits in t2, which makes it equals SELECT * FROM t1 UNION SELECT * FROM t1;

> SELECT a FROM t2 WHERE b = 12;
ERROR 1054 (42S22): Unknown column 'a' in 'field list'

@sylzd sylzd removed their assignment Aug 2, 2021
@winoros
Copy link
Member

winoros commented Nov 22, 2021

The apply operator ruins the meaning of ORDER BY constant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/minor sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants