# Copyright 2023 PingCAP, Inc.
#
# 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.

mysql> drop table if exists test.tx
mysql> create table test.tx( a int(11) NOT NULL,b varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, c varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL)
mysql> alter table test.tx set tiflash replica 1
mysql> insert into test.tx values (1, 'a', 'a'), (2, 'A ', 'a '), (3, 'A', 'A'), (4, 'a ', 'A ')
func> wait_table test tx

mysql> set session tidb_isolation_read_engines='tiflash'; select count(distinct b) from test.tx;
+-------------------+
| count(distinct b) |
+-------------------+
|                 1 |
+-------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select count(distinct c) from test.tx;
+-------------------+
| count(distinct c) |
+-------------------+
|                 2 |
+-------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select count(distinct b,c) from test.tx;
+---------------------+
| count(distinct b,c) |
+---------------------+
|                   2 |
+---------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select count(distinct c,b) from test.tx where a < 3;
+---------------------+
| count(distinct c,b) |
+---------------------+
|                   1 |
+---------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select approx_count_distinct(b) from test.tx;
+--------------------------+
| approx_count_distinct(b) |
+--------------------------+
|                        1 |
+--------------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select approx_count_distinct(c) from test.tx;
+--------------------------+
| approx_count_distinct(c) |
+--------------------------+
|                        2 |
+--------------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select approx_count_distinct(c,b) from test.tx;
+----------------------------+
| approx_count_distinct(c,b) |
+----------------------------+
|                          2 |
+----------------------------+

mysql> set session tidb_isolation_read_engines='tiflash'; select approx_count_distinct(b,c) from test.tx where a < 3;
+----------------------------+
| approx_count_distinct(b,c) |
+----------------------------+
|                          1 |
+----------------------------+
