Skip to content

Commit

Permalink
Fix incorrect result of max aggregation fun with collation ci (pingca…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Mar 16, 2023
1 parent 5d39778 commit d8cb780
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dbms/src/Core/SortCursor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <Columns/ColumnNullable.h>
#include <Columns/ColumnString.h>
#include <Columns/IColumn.h>
#include <Common/typeid_cast.h>
Expand Down Expand Up @@ -72,7 +73,7 @@ struct SortCursorImpl

sort_columns.push_back(block.safeGetByPosition(column_number).column.get());

need_collation[j] = desc[j].collator != nullptr && typeid_cast<const ColumnString *>(sort_columns.back()); /// TODO Nullable(String)
need_collation[j] = desc[j].collator != nullptr && typeid_cast<const ColumnString *>(std::get<0>(removeNullable(sort_columns.back())));
has_collation |= need_collation[j];
}

Expand Down
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions tests/fullstack-test/issues/issue_4519.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2022 PingCAP, Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Preparation.
=> DBGInvoke __init_fail_point()

mysql> drop table if exists test.test
mysql> create table test.test (col1 decimal(65, 10), col2 decimal(20, 20), col3 decimal(65, 0))
mysql> insert into test.test values(0.1,0.1,1),(1.0,0.1,1),(0,0,0),(null,null,null),(99.9,0.99,99)

mysql> alter table test.test set tiflash replica 1

func> wait_table test test

mysql> use test; set tidb_allow_mpp=1;set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select t1.col1, t2.col2 from test t1 join test t2 on t1.col1 = t2.col2;
+--------------+------------------------+
| col1 | col2 |
+--------------+------------------------+
| 0.1000000000 | 0.10000000000000000000 |
| 0.1000000000 | 0.10000000000000000000 |
| 0.0000000000 | 0.00000000000000000000 |
+--------------+------------------------+

mysql> use test; set tidb_allow_mpp=1;set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select t1.col1, t2.col3 from test t1 join test t2 on t1.col1 = t2.col3;
+--------------+------+
| col1 | col3 |
+--------------+------+
| 1.0000000000 | 1 |
| 1.0000000000 | 1 |
| 0.0000000000 | 0 |
+--------------+------+

# Clean up.
mysql> drop table if exists test.test
39 changes: 39 additions & 0 deletions tests/tidb-ci/new_collation_fullstack/issue_6807.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2023 PingCAP, Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Preparation.
mysql> drop table if exists test.t1
mysql> CREATE TABLE test.t1 (a varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,id int(11) NOT NULL,PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
mysql> insert into test.t1(a ,id) values('jlsf',1),(null,2),('YmkS',3),('0',4);
mysql> drop table if exists test.t2
mysql> CREATE TABLE test.t2 (a varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,b char(20) COLLATE utf8mb4_general_ci DEFAULT NULL,id int(11) NOT NULL,PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
mysql> insert into test.t2(a,b,id) values('yMKs','jlsf',1),('yyds','YmkS',2),('cc',4,3),(null,null,4),('abc',null,5),(null,'df',6);

mysql> alter table test.t1 set tiflash replica 1
mysql> alter table test.t2 set tiflash replica 1

func> wait_table test t1
func> wait_table test t2


mysql> use test; set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp=1; select max(a) from t1 where a in ( select b from t2 where a>b);
+--------+
| max(a) |
+--------+
| YmkS |
+--------+

# Clean up.
# mysql> drop table if exists test.t1
# mysql> drop table if exists test.t2

0 comments on commit d8cb780

Please sign in to comment.