Skip to content

Commit

Permalink
Support SEQUENCE_TABLE function
Browse files Browse the repository at this point in the history
  • Loading branch information
ani-sha committed Jan 30, 2025
1 parent 83cb847 commit 413f092
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit 413f092

Please sign in to comment.