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

union duplicate key #2873

Open
yaozhu opened this issue Jan 23, 2024 · 5 comments
Open

union duplicate key #2873

yaozhu opened this issue Jan 23, 2024 · 5 comments

Comments

@yaozhu
Copy link

yaozhu commented Jan 23, 2024

mysql table baseall and table test has the same tale struct and recored

show create table baseall;
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| baseall | CREATE TABLE baseall (
k0 tinyint(1) DEFAULT NULL,
k1 tinyint DEFAULT NULL,
k2 smallint DEFAULT NULL,
k3 int DEFAULT NULL,
k4 bigint DEFAULT NULL,
k5 decimal(9,3) DEFAULT NULL,
k6 char(5) DEFAULT NULL,
k10 date DEFAULT NULL,
k11 datetime DEFAULT NULL,
k7 varchar(20) DEFAULT NULL,
k8 double DEFAULT NULL,
k9 float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

show create table test;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE test (
k0 tinyint(1) DEFAULT NULL,
k1 tinyint DEFAULT NULL,
k2 smallint DEFAULT NULL,
k3 int DEFAULT NULL,
k4 bigint DEFAULT NULL,
k5 decimal(9,3) DEFAULT NULL,
k6 char(5) DEFAULT NULL,
k10 date DEFAULT NULL,
k11 datetime DEFAULT NULL,
k7 varchar(20) DEFAULT NULL,
k8 double DEFAULT NULL,
k9 float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

execute sql as follow:
SELECT *
FROM
(SELECT *
FROM
(SELECT k1, k2, k3, k4, k5, k6, k10, k11, k7, k8, k9
FROM test.baseall) AS t
LEFT JOIN
(SELECT k1, k2, k3, k4, k5, k6, k10, k11, k7, k8, k9
FROM test.test) AS t0
ON
t.k1 = t0.k1
UNION
SELECT *
FROM
(SELECT k1, k2, k3, k4, k5, k6, k10, k11, k7, k8, k9
FROM test.baseall) AS t1
RIGHT JOIN
(SELECT k1, k2, k3, k4, k5, k6, k10, k11, k7, k8, k9
FROM test.test) AS t2
ON
t1.k1 = t2.k1) AS t
LIMIT 1000

report error Duplicated inline view column alias k1 in inline view t

@yaozhu yaozhu added the bug label Jan 23, 2024
@cgivre
Copy link
Contributor

cgivre commented Jan 23, 2024

Can you please provide a screenshot or some explanation that is more clear? This is really difficult to follow.

@cgivre cgivre added to-be-verified and removed bug labels Jan 23, 2024
@yaozhu
Copy link
Author

yaozhu commented Jan 23, 2024

Can you please provide a screenshot or some explanation that is more clear? This is really difficult to follow.

image

@yaozhu
Copy link
Author

yaozhu commented Jan 23, 2024

@cgivre are u clear?

@cgivre
Copy link
Contributor

cgivre commented Jan 23, 2024

I'm not yet convinced there is a bug in Drill here. I think the issue may actually be in your query. My hunch here is that there may be an issue in the ORDER BY statement. Your inner tables each have columns called k1. Then you are calling a sort on that without specifying which one it is. You might first try adding table names to the ORDER BY clause.

Secondly, I'm not trying to be rude but what are you trying to achieve with this query? It looks like you are performing a union of a left and right join of the same table? Why not combine these? Then you have nested SELECT * statements that don't really seem to serve any purpose.

@yaozhu
Copy link
Author

yaozhu commented Jan 23, 2024

This is a test case written by testers, without actual usage scenarios. What do you mean by combining them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants