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

fix(tianmu): fix result of the query using the subquery derived table is incorrect (#1662) #1688

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
52 changes: 52 additions & 0 deletions mysql-test/suite/tianmu/r/issue1662.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Create test database
CREATE DATABASE IF NOT EXISTS test_db_1662;
USE test_db_1662;
# Create test table with tianmu engine
CREATE TABLE IF NOT EXISTS test_table (
id INT,
value INT,
PRIMARY KEY (id)
) ENGINE=tianmu;
# Insert data into test table
INSERT INTO test_table (id, value) VALUES
(1, 10),
(2, 20),
(3, 10),
(4, 30),
(5, 20);
# Select data from test table with user-defined variable
SELECT
id,
value,
@my_var := IF(value = @prev_value, @my_var, @my_var + 1) AS group_id,
@prev_value := value
FROM
test_table,
(SELECT @my_var := 0, @prev_value := NULL) AS init
ORDER BY
value,
id;
id value group_id @prev_value := value
1 10 2 10
3 10 2 10
2 20 4 20
5 20 4 20
4 30 6 30
SELECT
id,
value,
@my_var := IF(id = @prev_value, @my_var, @my_var + 1) AS group_id,
@prev_value := value
FROM
test_table,
(SELECT @my_var := 0, @prev_value := NULL) AS init
ORDER BY
value,
id;
id value group_id @prev_value := value
1 10 2 10
3 10 4 10
2 20 6 20
5 20 8 20
4 30 10 30
DROP DATABASE test_db_1662;
53 changes: 53 additions & 0 deletions mysql-test/suite/tianmu/t/issue1662.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--source include/have_tianmu.inc

--disable_warnings

--let $my_var = 0

--echo # Create test database
CREATE DATABASE IF NOT EXISTS test_db_1662;

USE test_db_1662;

--echo # Create test table with tianmu engine
CREATE TABLE IF NOT EXISTS test_table (
id INT,
value INT,
PRIMARY KEY (id)
) ENGINE=tianmu;

--echo # Insert data into test table
INSERT INTO test_table (id, value) VALUES
(1, 10),
(2, 20),
(3, 10),
(4, 30),
(5, 20);

--echo # Select data from test table with user-defined variable
SELECT
id,
value,
@my_var := IF(value = @prev_value, @my_var, @my_var + 1) AS group_id,
@prev_value := value
FROM
test_table,
(SELECT @my_var := 0, @prev_value := NULL) AS init
ORDER BY
value,
id;

SELECT
id,
value,
@my_var := IF(id = @prev_value, @my_var, @my_var + 1) AS group_id,
@prev_value := value
FROM
test_table,
(SELECT @my_var := 0, @prev_value := NULL) AS init
ORDER BY
value,
id;

DROP DATABASE test_db_1662;

2 changes: 1 addition & 1 deletion storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE
}

if (exec_direct) {
if ((!selects_list->table_list.elements) && (selects_list->fields_list.elements)) {
if ((selects_list->fields_list.elements)) {
List_iterator_fast<Item> li(selects_list->fields_list);
for (Item *item = li++; item; item = li++) {
if ((item->type() == Item::Type::FUNC_ITEM) &&
Expand Down