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

The result of where <string> is wrong because it will be converted to int type. #3447

Closed
lilinghai opened this issue Nov 16, 2021 · 2 comments · Fixed by #3463
Closed

The result of where <string> is wrong because it will be converted to int type. #3447

lilinghai opened this issue Nov 16, 2021 · 2 comments · Fixed by #3463

Comments

@lilinghai
Copy link

release-5.3

create table t(a float,b double);
alter table t set tiflash replica 2;
insert into t values(0.1,0.2),(0.2,0.2);
set @@tidb_enforce_mpp=on;
select count(*) from t group by a having case when count(*) then sum(b) else 'a' end; -- expect 1,1 ; but got empty result
/*
mysql> explain select count(*) from t group by a having case when count(*) then sum(b) else 'a' end;
+----------------------------------------+---------+-------------------+---------------+----------------------------------------------------------------------------------------------+
| id                                     | estRows | task              | access object | operator info                                                                                |
+----------------------------------------+---------+-------------------+---------------+----------------------------------------------------------------------------------------------+
| TableReader_48                         | 1.28    | root              |               | data:ExchangeSender_47                                                                       |
| └─ExchangeSender_47                    | 1.28    | batchCop[tiflash] |               | ExchangeType: PassThrough                                                                    |
|   └─Projection_7                       | 1.28    | batchCop[tiflash] |               | Column#4                                                                                     |
|     └─Selection_39                     | 1.28    | batchCop[tiflash] |               | case(Column#4, cast(Column#5, var_string(5)), "a")                                           |
|       └─Projection_43                  | 1.60    | batchCop[tiflash] |               | Column#4, Column#5                                                                           |
|         └─HashAgg_44                   | 1.60    | batchCop[tiflash] |               | group by:aggregation2.t.a, funcs:sum(Column#13)->Column#4, funcs:sum(Column#14)->Column#5    |
|           └─ExchangeReceiver_46        | 1.60    | batchCop[tiflash] |               |                                                                                              |
|             └─ExchangeSender_45        | 1.60    | batchCop[tiflash] |               | ExchangeType: HashPartition, Hash Cols: [name: aggregation2.t.a, collate: N/A]               |
|               └─HashAgg_41             | 1.60    | batchCop[tiflash] |               | group by:aggregation2.t.a, funcs:count(1)->Column#13, funcs:sum(aggregation2.t.b)->Column#14 |
|                 └─TableFullScan_29     | 2.00    | batchCop[tiflash] | table:t       | keep order:false, stats:pseudo                                                               |
+----------------------------------------+---------+-------------------+---------------+----------------------------------------------------------------------------------------------+
10 rows in set (0.04 sec)
@lilinghai lilinghai added type/bug The issue is confirmed as a bug. severity/major labels Nov 16, 2021
@LittleFall
Copy link
Contributor

LittleFall commented Nov 16, 2021

minimal reproduce:

create table t(a char(5));
alter table t set tiflash replica 1;
insert into t values ('0.1');
mysql> select /*+ read_from_storage(tiflash[t]) */ * from t where a;
Empty set (0.01 sec)

@LittleFall LittleFall self-assigned this Nov 16, 2021
@LittleFall
Copy link
Contributor

LittleFall commented Nov 17, 2021

root cause:

the semantics of where a is similar than where a != 0, which is done in function DAGExpressionAnalyzer::convertToUInt8. but when a is string type, this function will add a castToInt, which will convert 0.1 to 0, that's not compatible with tidb/tikv. we should add a castToDouble instead.

@LittleFall LittleFall changed the title The result of case when function is wrong in some boundary conditions The result of where <string> is wrong in some boundary conditions. Nov 17, 2021
@LittleFall LittleFall changed the title The result of where <string> is wrong in some boundary conditions. The result of where <string> is wrong because it will be converted to int type. Nov 17, 2021
ti-chi-bot added a commit that referenced this issue Apr 14, 2022
ti-chi-bot added a commit that referenced this issue Apr 15, 2022
ti-chi-bot added a commit that referenced this issue Jun 17, 2022
ti-chi-bot added a commit that referenced this issue Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants