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

Run sql failed when using replace function #9522

Closed
EricZequan opened this issue Oct 12, 2024 · 0 comments · Fixed by #9615 · May be fixed by #9536
Closed

Run sql failed when using replace function #9522

EricZequan opened this issue Oct 12, 2024 · 0 comments · Fixed by #9615 · May be fixed by #9536
Assignees
Labels
affects-8.5 This bug affects the 8.5.x(LTS) versions. component/compute severity/major type/bug The issue is confirmed as a bug.

Comments

@EricZequan
Copy link
Contributor

Bug Report

When using the replace function in complex SQL, it may be affected by the where condition, causing the replace function to fail when pushed down to Tiflash for execution.
For example,

SELECT /*+ read_from_storage(tiflash[my_table]) */ REPLACE(my_table.col14, my_table.col_11, my_table.col_14) FROM my_table where my_table.col14 in 'TEST SQL';

This statement will replace the replace function's parameter with the filter parameter when it is pushed down to improve SQL execution efficiency. Unfortunately, Tiflash only supports the replace function first parameter to be of type ColumnString.

1. Minimal reproduce step (Required)

mysql> CREATE TABLE my_table (
         `col_11` VARCHAR(255) NOT NULL,
         `col_12` int(10) unsigned NOT NULL,
         `col_13` VARCHAR(255) NOT NULL,
         `col_14` VARCHAR(255) NOT NULL
     );
Query OK, 0 rows affected (0.02 sec)

mysql> insert into my_table values ('World',1203945,'Hello, World!','FOR TEST'), ('ttttt',1122,'bbbbb','cccc');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT      /*+ read_from_storage(tiflash[my_table]) */      REPLACE(my_table.col_13, my_table.col_11, my_table.col_13)  FROM      my_table;
+------------------------------------------------------------+
| REPLACE(my_table.col_13, my_table.col_11, my_table.col_13) |
+------------------------------------------------------------+
| Hello, Hello, World!!                                      |
+------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select * from my_table;
+--------+---------+---------------+----------+
| col_11 | col_12  | col_13        | col_14   |
+--------+---------+---------------+----------+
| World  | 1203945 | Hello, World! | FOR TEST |
| ttttt  |    1122 | bbbbb         | cccc     |
+--------+---------+---------------+----------+
2 rows in set (0.00 sec)

mysql> select replace('Hello World',my_table.col_11, my_table.col_14) from my_table;
+---------------------------------------------------------+
| replace('Hello World',my_table.col_11, my_table.col_14) |
+---------------------------------------------------------+
| Hello FOR TEST                                          |
| Hello World                                             |
+---------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> explain select replace('Hello World',my_table.col_11, my_table.col_14) from my_table;
+-------------------------+---------+-----------+----------------+----------------------------------------------------------------------------+
| id                      | estRows | task      | access object  | operator info                                                              |
+-------------------------+---------+-----------+----------------+----------------------------------------------------------------------------+
| Projection_3            | 2.00    | root      |                | replace(Hello World, test.my_table.col_11, test.my_table.col_14)->Column#6 |
| └─TableReader_6         | 2.00    | root      |                | data:TableFullScan_5                                                       |
|   └─TableFullScan_5     | 2.00    | cop[tikv] | table:my_table | keep order:false, stats:pseudo                                             |
+-------------------------+---------+-----------+----------------+----------------------------------------------------------------------------+
3 rows in set (0.00 sec)

mysql> ALTER TABLE my_table SET TIFLASH REPLICA 1;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT /*+ read_from_storage(tiflash[my_table]) */ REPLACE('Hello World', my_table.col_11, my_table.col_14)  FROM my_table;
ERROR 1105 (HY000): other error for mpp stream: Code: 44, e.displayText() = DB::Exception: Illegal column Const(String) of first argument of function replaceAll, e.what() = DB::Exception,



mysql> explain SELECT /*+ read_from_storage(tiflash[my_table]) */     REPLACE('Hello World', my_table.col_11, my_table.col_14)  FROM my_table;
+---------------------------+---------+--------------+----------------+----------------------------------------------------------------------------+
| id                        | estRows | task         | access object  | operator info                                                              |
+---------------------------+---------+--------------+----------------+----------------------------------------------------------------------------+
| TableReader_10            | 2.00    | root         |                | MppVersion: 2, data:ExchangeSender_9                                       |
| └─ExchangeSender_9        | 2.00    | mpp[tiflash] |                | ExchangeType: PassThrough                                                  |
|   └─Projection_4          | 2.00    | mpp[tiflash] |                | replace(Hello World, test.my_table.col_11, test.my_table.col_14)->Column#6 |
|     └─TableFullScan_8     | 2.00    | mpp[tiflash] | table:my_table | keep order:false, stats:pseudo                                             |
+---------------------------+---------+--------------+----------------+----------------------------------------------------------------------------+
4 rows in set (0.00 sec)

2. What did you expect to see? (Required)

Query OK.

3. What did you see instead (Required)

ERROR 1105 (HY000): other error for mpp stream: Code: 44, e.displayText() = DB::Exception: Illegal column Const(String) of first argument of function replaceAll, e.what() = DB::Exception,

4. What is your TiFlash version? (Required)

master

@EricZequan EricZequan added the type/bug The issue is confirmed as a bug. label Oct 12, 2024
@ti-chi-bot ti-chi-bot bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@guo-shaoge guo-shaoge self-assigned this Nov 12, 2024
ti-chi-bot bot added a commit that referenced this issue Nov 18, 2024
close #9522

1. remove some useless arguments(pos, occ, match_type)
2. support first argument as ColumnConst

Signed-off-by: guo-shaoge <shaoge1994@163.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
ti-chi-bot bot pushed a commit that referenced this issue Nov 18, 2024
…9646)

close #9522

1. remove some useless arguments(pos, occ, match_type)
2. support first argument as ColumnConst

Signed-off-by: guo-shaoge <shaoge1994@163.com>

Co-authored-by: guo-shaoge <shaoge1994@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-8.5 This bug affects the 8.5.x(LTS) versions. component/compute severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants