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 up the problem of adding 2 to the user-defined variable each time and fix up a crash when executing multiple nested queries with user-defined variable (#1897)(#1913) #1935

Merged
merged 1 commit into from
Jul 13, 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
20 changes: 10 additions & 10 deletions mysql-test/suite/tianmu/r/issue1662.result
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ 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
1 10 1 10
3 10 1 10
2 20 2 20
5 20 2 20
4 30 3 30
SELECT
id,
value,
Expand All @@ -44,9 +44,9 @@ 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
1 10 1 10
3 10 2 10
2 20 3 20
5 20 4 20
4 30 5 30
DROP DATABASE test_db_1662;
51 changes: 51 additions & 0 deletions mysql-test/suite/tianmu/r/issue1897.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
DROP DATABASE IF EXISTS issue1897;
CREATE DATABASE issue1897;
USE issue1897;
CREATE TABLE t1 (id INT, name VARCHAR(5));
INSERT INTO t1 VALUES (1,'AAA'),(2,'BBB');
INSERT INTO t1 VALUES (1,'AAA'),(2,'BBB');
SELECT @row := @row + 1 FROM t1,(SELECT @row := 0) a;
@row := @row + 1
1
2
3
4
SELECT @rownum1 := @rownum1 + 1 inde FROM (SELECT a.* FROM t1 a) a,(SELECT @rownum1 := 0, @pxydm1 := NULL,
@rankno1 := 0) b;
inde
1
2
3
4
SELECT
id,
name,
@my_var := IF(name = @prev_value, @my_var, @my_var + 1) AS group_id,
@prev_value := name
FROM
t1,
(SELECT @my_var := 0, @prev_value := NULL) AS init
ORDER BY
name,
id;
id name group_id @prev_value := name
1 AAA 1 AAA
1 AAA 1 AAA
2 BBB 2 BBB
2 BBB 2 BBB
SELECT B.name, A.id, 1 sort_no
FROM t1 A
INNER JOIN t1 B
ON A.id = B.id
INNER JOIN (SELECT * FROM (SELECT @row := @row + 1 AS rowno FROM (SELECT 0) C) D) E ON 1 = 1;
name id sort_no
AAA 1 1
AAA 1 1
BBB 2 1
BBB 2 1
AAA 1 1
AAA 1 1
BBB 2 1
BBB 2 1
DROP TABLE t1;
DROP DATABASE issue1897;
39 changes: 39 additions & 0 deletions mysql-test/suite/tianmu/t/issue1897.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--source include/have_tianmu.inc
--disable_warnings

DROP DATABASE IF EXISTS issue1897;
CREATE DATABASE issue1897;
USE issue1897;
--enable_warnings

CREATE TABLE t1 (id INT, name VARCHAR(5));

INSERT INTO t1 VALUES (1,'AAA'),(2,'BBB');
INSERT INTO t1 VALUES (1,'AAA'),(2,'BBB');

SELECT @row := @row + 1 FROM t1,(SELECT @row := 0) a;

SELECT @rownum1 := @rownum1 + 1 inde FROM (SELECT a.* FROM t1 a) a,(SELECT @rownum1 := 0, @pxydm1 := NULL,
@rankno1 := 0) b;

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

SELECT B.name, A.id, 1 sort_no
FROM t1 A
INNER JOIN t1 B
ON A.id = B.id
INNER JOIN (SELECT * FROM (SELECT @row := @row + 1 AS rowno FROM (SELECT 0) C) D) E ON 1 = 1;

DROP TABLE t1;

DROP DATABASE issue1897;
4 changes: 4 additions & 0 deletions storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ bool TABLE_LIST::optimize_derived_for_tianmu(THD *thd) {

SELECT_LEX_UNIT *const unit = derived_unit();

if (unit->is_optimized()) {
DBUG_RETURN(true);
}

assert(unit && unit->is_prepared() && !unit->is_optimized());

if (unit && unit->is_prepared() && !unit->is_optimized()) {
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/vc/expr_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int64_t ExpressionColumn::GetValueInt64Impl(const core::MIIterator &mit) {
bool ExpressionColumn::IsNullImpl(const core::MIIterator &mit) {
{
Item *item = expr_->GetItem();
if (item && (Item::FUNC_ITEM == item->type()) && (dynamic_cast<Item_func_if *>(item))) {
if ((item && (Item::FUNC_ITEM == item->type()) && (dynamic_cast<Item_func_if *>(item))) || !deterministic_) {
return false;
}
}
Expand Down