feat(optimizer)!: annotate regexpreplace for mysql#7948
Open
PiyaDaswadkar wants to merge 2 commits into
Open
Conversation
treysp
requested changes
Jul 24, 2026
| } | ||
| }, | ||
| **{ | ||
| expr_type: {"returns": exp.DType.LONGTEXT} |
Collaborator
There was a problem hiding this comment.
It looks like REGEXP_REPLACE has signatures for binary inputs that all return LONGBLOB, so we'll need to use an annotator to conditionally set the return type based on the input arg types.
All three of this, expression, and replacement must have the same general type family (either text or binary).
There are 4 possible text and 6 possible binary input types:
mysql> CREATE TABLE regex_test_inputs (
-> c_text TEXT,
-> c_tinytext TINYTEXT,
-> c_mediumtext MEDIUMTEXT,
-> c_longtext LONGTEXT,
-> c_binary BINARY(3),
-> c_varbinary VARBINARY(3),
-> c_blob BLOB,
-> c_tinyblob TINYBLOB,
-> c_mediumblob MEDIUMBLOB,
-> c_longblob LONGBLOB
-> );
Query OK, 0 rows affected (0.010 sec)
mysql>
-> INSERT INTO regex_test_inputs VALUES (
-> 'abc',
-> 'abc',
-> 'abc',
-> 'abc',
-> X'616263', -- abc
-> X'616263',
-> X'616263',
-> X'616263',
-> X'616263',
-> X'616263'
-> );
Query OK, 1 row affected (0.001 sec)
mysql>
-> CREATE TABLE regex_test_results AS SELECT
-> REGEXP_REPLACE(c_text, 'a', 'z') AS from_text,
-> REGEXP_REPLACE(c_tinytext, 'a', 'z') AS from_tinytext,
-> REGEXP_REPLACE(c_mediumtext, 'a', 'z') AS from_mediumtext,
-> REGEXP_REPLACE(c_longtext, 'a', 'z') AS from_longtext,
-> REGEXP_REPLACE(c_binary, X'62', X'78') AS from_binary,
-> REGEXP_REPLACE(c_varbinary,X'62', X'78') AS from_varbinary,
-> REGEXP_REPLACE(c_tinyblob, X'62', X'78') AS from_tinyblob,
-> REGEXP_REPLACE(c_blob, X'62', X'78') AS from_blob,
-> REGEXP_REPLACE(c_mediumblob, X'62', X'78') AS from_mediumblob,
-> REGEXP_REPLACE(c_longblob, X'62', X'78') AS from_longblob
-> FROM regex_test_inputs;
Query OK, 1 row affected (0.005 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> DESCRIBE regex_test_results;
+-----------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+----------+------+-----+---------+-------+
| from_text | longtext | YES | | NULL | |
| from_tinytext | longtext | YES | | NULL | |
| from_mediumtext | longtext | YES | | NULL | |
| from_longtext | longtext | YES | | NULL | |
| from_binary | longblob | YES | | NULL | |
| from_varbinary | longblob | YES | | NULL | |
| from_tinyblob | longblob | YES | | NULL | |
| from_blob | longblob | YES | | NULL | |
| from_mediumblob | longblob | YES | | NULL | |
| from_longblob | longblob | YES | | NULL | |
+-----------------+----------+------+-----+---------+-------+
10 rows in set (0.003 sec)
Contributor
Author
There was a problem hiding this comment.
Thanks for the suggestion. I’ve added the binary-family fixtures for REGEXP_REPLACE, covering the same optional argument combinations as the text-family tests. The tests now cover both LONGTEXT and LONGBLOB return types based on the argument family.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR annotate the function RegexpReplace for mysql
https://dev.mysql.com/doc/refman/9.7/en/regexp.html#function_regexp-replace