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

Support SEQUENCE_TABLE function #4403

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sql/mysql/Positive-Technologies/MySqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ OCT : 'OCT';
OCTET_LENGTH : 'OCTET_LENGTH';
ORD : 'ORD';
OVERLAPS : 'OVERLAPS';
PERCONA_SEQUENCE_TABLE : 'PERCONA_SEQUENCE_TABLE';
PERIOD_ADD : 'PERIOD_ADD';
PERIOD_DIFF : 'PERIOD_DIFF';
PI : 'PI';
Expand All @@ -1094,6 +1095,7 @@ RTRIM : 'RTRIM';
SEC_TO_TIME : 'SEC_TO_TIME';
SECONDARY_ENGINE : 'SECONDARY_ENGINE';
SECONDARY_ENGINE_ATTRIBUTE : 'SECONDARY_ENGINE_ATTRIBUTE';
SEQUENCE_TABLE : 'SEQUENCE_TABLE';
SESSION_USER : 'SESSION_USER';
SHA : 'SHA';
SHA1 : 'SHA1';
Expand Down
8 changes: 8 additions & 0 deletions sql/mysql/Positive-Technologies/MySqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ tableSource

tableSourceItem
: tableName (PARTITION '(' uidList ')')? (AS? alias = uid)? (indexHint (',' indexHint)*)? # atomTableItem
| sequenceFunctionName '(' DECIMAL_LITERAL ')' (AS? alias = uid)? # sequenceTableItem
| (selectStatement | '(' parenthesisSubquery = selectStatement ')') AS? alias = uid # subqueryTableItem
| '(' tableSources ')' # tableSourcesItem
;
Expand Down Expand Up @@ -2487,6 +2488,11 @@ partitionClause
: PARTITION BY expression (',' expression)*
;

sequenceFunctionName
: SEQUENCE_TABLE
| PERCONA_SEQUENCE_TABLE
;

scalarFunctionName
: functionNameBase
| ASCII
Expand Down Expand Up @@ -2988,6 +2994,7 @@ keywordsCanBeId
| PASSWORDLESS_USER_ADMIN
| PASSWORD_LOCK_TIME
| PATH
| PERCONA_SEQUENCE_TABLE
| PERSIST_RO_VARIABLES_ADMIN
| PHASE
| PLUGINS
Expand Down Expand Up @@ -3050,6 +3057,7 @@ keywordsCanBeId
| SCHEMA_NAME
| SECURITY
| SECONDARY_ENGINE_ATTRIBUTE
| SEQUENCE_TABLE
| SERIAL
| SERVER
| SESSION
Expand Down
15 changes: 15 additions & 0 deletions sql/mysql/Positive-Technologies/examples/ddl_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ CREATE TABLE `TABLE1` (
PRIMARY KEY (`COL1`, `COL2`, `COL3`),
CLUSTERING KEY `CLKEY1` (`COL3`, `COL2`))
ENGINE=TOKUDB DEFAULT CHARSET=CP1251;

CREATE TABLE T1 (NAME VARCHAR(36), SEQUENCE_TABLE BIGINT NOT NULL);

#end
#begin
-- Rename table
Expand Down Expand Up @@ -892,4 +895,16 @@ BEGIN
SET AI.COL_1 = NULL
LIMIT 500;
END
#end

#begin
CREATE DEFINER=`bcadmin`@`%` PROCEDURE `sp_next_available_otc_instance_strategy_id`()
BEGIN
SELECT MIN(st.value) AS strategy_id
FROM SEQUENCE_TABLE(100000) ST
JOIN btc_quant.stratId_ranges r ON r.stratId0 <= st.value AND st.value < r.stratId1
LEFT JOIN otc_instance i ON i.strategy_id=st.value
WHERE r.category = 'otc' AND now() BETWEEN validFromDate AND COALESCE(validToDate, now())
AND i.strategy_id IS NULL;
END
#end
Loading