Repository navigation
Conversation
CHANGE REPLICATION SOURCE TO, CHANGE REPLICATION FILTER, START REPLICA, STOP REPLICA, RESET REPLICA, RESET BINARY LOGS AND GTIDS and PURGE BINARY LOGS failed to parse, so a replica setup script failed at its first statement. The new statements of net.sf.jsqlparser.statement.replication follow the MySQL 8.4 grammar. ReplicationSourceOption extends ReplicationOption, and each option kind says which value it takes: a string, a number, NULL, 0 or 1, a keyword, the server ID list or an account. ReplicationFilter keeps database names, tables, patterns or rewrite pairs, and the statements share one FOR CHANNEL production. RESET reads MySQL's comma list into ResetReplicationStatement, apart from ResetStatement. PurgeStatement gains BINARY LOGS TO and BEFORE, which MariaDB also reads, with its MASTER LOGS; as in MySQL, BEFORE takes no subquery. Without a dialect a bare RESET REPLICA stays a ResetStatement, and other dialects keep their readings. STOP becomes a non-reserved keyword and remains usable as a name, also in Oracle's PURGE TABLESPACE. Signed-off-by: minleejae <mmj9808@gmail.com>
This branch has not been deployed
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.
Purpose
The MySQL statements that set up and run replication failed to parse, so a replica setup script
failed at its first statement:
CHANGEandSTOPwere not statement starts,STARTonly beganSTART TRANSACTION,RESETonly took a parameter name (RESET REPLICA ALLfailed atALL), andPURGEonly knewOracle's objects.
Current design (As-is)
ResetStatementis the PostgreSQLRESET name | ALL | TIME ZONE.RESET REPLICAhappens toparse as the reset of a parameter named
REPLICA.PurgeStatementmodels Oracle'sPURGE TABLE | INDEX | RECYCLEBIN | DBA_RECYCLEBIN | TABLESPACE, keyed byPurgeObjectType.ReplicationOption<K>is the base of the PostgreSQL publication and subscription options: aspelled name, a typed kind and an
Expressionvalue.threads or
FOR CHANNEL.Target design (To-be)
CHANGE REPLICATION SOURCE TO.
ChangeReplicationSourceStatementholdsReplicationSourceOptions, which extendReplicationOption<Kind>.Kindlists the 37options of MySQL 8.4, and
Kind.getValueType()says what each takes, followingsql_yacc.yy:NULL;0or1(GTID_ONLYandSOURCE_CONNECTION_AUTO_FAILOVER, where MySQL reports any othervalue as a syntax error);
IGNORE_SERVER_IDS = (1, 2);NULL;STREAM | ON | OFF | GENERATE;OFF | LOCAL | 'uuid'.A value of another type is a parse error, as it is in MySQL. Keyword values are kept as a
Column, likeONin the PostgreSQL options.PRIVILEGE_CHECKS_USERkeeps its account ingetAccount()(theUserAccountofCREATE USER).getPrimaryKeyCheck()andgetGtidAssignment()read the keyword options as enums.CHANGE REPLICATION FILTER.
ChangeReplicationFilterStatementholdsReplicationFilterrules. Each rule's list may be empty and holds what its kind takes:
REPLICATE_DO_DB,REPLICATE_IGNORE_DB);db.tablenames asTable(REPLICATE_DO_TABLE,REPLICATE_IGNORE_TABLE);REPLICATE_WILD_DO_TABLE,REPLICATE_WILD_IGNORE_TABLE);(from, to)pairs (REPLICATE_REWRITE_DB = ((a, b), (c, d))).START / STOP REPLICA.
StartReplicaStatementandStopReplicaStatementkeep their threads(
IO_THREAD,SQL_THREAD).START REPLICAalso keeps:UNTILconditions asReplicaUntilOptions. The first may be any condition, and laterones only log coordinates, as in the server grammar;
USER,PASSWORD,DEFAULT_AUTHandPLUGIN_DIRstrings, in the server's order.RESET.
ResetReplicationStatementholds the comma list of MySQL'sRESETstatement:BINARY LOGS AND GTIDS [TO n]andREPLICA [ALL] [FOR CHANNEL 'c'], as inRESET REPLICA, BINARY LOGS AND GTIDS.ResetStatementis not changed.PURGE.
PurgeStatementgains the additivePurgeObjectType.BINARY_LOGS, aLogBound(
TO,BEFORE) andgetLogExpression(), which is the log name literal or theBEFOREexpression.
getObject()returns the same expression. MySQL parsesBEFOREwith subqueriesdisallowed, so a subquery anywhere in it is a parse error:
PURGE BINARY LOGS BEFORE NOW() + (SELECT 1)is rejected, whileBEFORE (NOW())andBEFORE @cutoffare accepted. The Oracle forms are unchanged.FOR CHANNEL. One
ReplicationChannel()production serves every statement. Followingopt_channel, the channel is a string, kept as aStringValueingetChannel().Dialects.
Dialect.MYSQLand the parser without a dialect read these forms.RESET REPLICAstays theResetStatementit is today.ALL,FOR CHANNELor a further reset option after it makes it MySQL's.Dialect.MARIADBreadsPURGE BINARY LOGSand MariaDB'sPURGE MASTER LOGS(
PurgeObjectType.MASTER_LOGS). MariaDB writes the other replication statementsdifferently (
CHANGE MASTER, connection names,MASTER_options), so they keep today'sreadings there.
CHANGE MASTER TO,START SLAVE,RESET MASTERand theMASTER_options, so they stay unsupported.
RESET,PURGEandSTART.STOPbecomes a non-reserved keyword and stays usable as a name.REPLICA,REPLICATION,SOURCE,CHANNELandLOGSremain identifiers.PURGE TABLESPACE name [USER name]read both names as plain identifiers. It nowreads them as object names, so
PURGE TABLESPACE stopkeeps parsing; quoted names areaccepted as well.
Wiring. The following all handle the new statements:
StatementDeParser, through each model'sappendTo, with valuespassing through the expression deparser;
TablesNamesFinder, which reports the tables ofREPLICATE_DO_TABLEandREPLICATE_IGNORE_TABLE;MODIFIES_SESSION, as forALTER SYSTEM;changeReplicationSource,changeReplicationFilter,startReplica,stopReplica,resetReplicationandpurgeBinaryLogs. The MySQLcapabilities enable all six, and MariaDB enables
purgeBinaryLogs.References:
CHANGE REPLICATION SOURCE TO,
CHANGE REPLICATION FILTER,
START REPLICA,
STOP REPLICA,
RESET,
RESET BINARY LOGS AND GTIDS,
RESET REPLICA,
PURGE BINARY LOGS,
MariaDB PURGE BINARY LOGS.
Not included, all spellings the server accepts that are rarely written:
RELAY_THREADsynonym ofIO_THREAD;0x…) as option values;ANSI_QUOTESmode;IGNORE_SERVER_IDS = (, 1)that the server's grammar lets through.Validation
129 new tests: 126 in
MySqlReplicationStatementsTestand 3 inReplicationStatementValidatorTest. They cover each form with and without the MySQL dialect,toString,StatementDeParser, reparsing, the AST fields, 60 rejected forms (among themsubqueries in
PURGE BINARY LOGS BEFORE), the readingskept in PostgreSQL, Oracle and MariaDB, statement boundaries and unsupported-statement
scripts,
STOPas a name,TablesNamesFinder, feature analysis, node ranges and building incode.
ASTNodeCoverageTestchecks seven new statements. The new tests fail onmaster, whereevery new form is a parse error.
spotlessApply cleanTest check jar: 13,067 tests, 25 skipped, 0 failures. Grammar ambiguitycheck, Checkstyle, PMD, SpotBugs and JaCoCo pass.
Compared with
master(a30a67920) on the DDL/DCL survey corpora: 0 regressions.Compared with
master(a30a67920) on the non-DDL MySQL corpus:Compared with
master(a30a67920) on the PostgreSQL corpora: no changes.MySQL 8.4.11 accepts all 55 statements the tests accept for the MySQL dialect, 53 of which
masterrejects. Some fail only when run, for exampleTarget log not found in binlog,Multiple channels exist on the replicaorReplica channel 'c1' does not exist. This includes the comma lists ofRESET, everyCHANGE REPLICATION SOURCE TOoption with its value type, empty filter lists and theSTART REPLICAconnection options. It reports a syntax error (1064) for all 60 statements the tests reject, includingGTID_ONLY = 2,SOURCE_HOST = NULL, an unquoted channel name, a subquery inPURGE BINARY LOGS BEFORE, andSTART SLAVE/CHANGE MASTER TO, which MySQL 8.4 removed.PostgreSQL 18.6 still reads
RESET REPLICAas resetting a configuration parameter (it fails only withunrecognized configuration parameter "replica"), and reports a syntax error for the MySQL replication statements.AI assistance: prepared with Claude Code.