Bug #109522 Feature request: have an "explode" command
Submitted: 3 Jan 2023 21:42 Modified: 4 Jan 2023 5:03
Reporter: Justin Levene Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S4 (Feature request)
Version:8.0.30 OS:Any
Assigned to: CPU Architecture:Any
Tags: explode, IN, values

[3 Jan 2023 21:42] Justin Levene
Description:
MySQL really needs a simple "EXPLODE(delimiter, string)" command to return rows of values to enable efficient use of "IN".

Functions can't use PREPARE, and FIND_IN_SET does not efficiently use indexed fields, so if you have lets say a comma list of values, the current ways to do it are:

set_ids = "1,2,3,4,5,6";
where FIND_IN_SET(`ID`, ids)

OR USING THE INDEXES MORE EFFICIENTLY USING IN:

set ids = "[1,2,3,4,5,6]";
...
where `ID` in (select `id` from JSON_TABLE(`ids`, "$[*]" COLUMNS(`id` BIGINT PATH "$"))`jt`)

The second option is clunky and it would be far better and easier to have something like:

set ids = "1,2,3,4,5,6";
...
where `ID` in (explode(",", ids));

Using the explode method enables the "IN" to be used, which is far more efficient than FIND_IN_SET or creating values from a JSON_TABLE.

How to repeat:
set ids = "1,2,3,4,5,6";
select ids;

-> "1,2,3,4,5,6"

select explode(",", ids);

-> 1
-> 2
-> 3
-> 4
-> 5
-> 6

Suggested fix:
Add an "EXPLODE" command to break a string list into values (rows).
[4 Jan 2023 5:03] MySQL Verification Team
Hello Justin Levene,

Thank you for the feature request.

regards,
Umesh