Skip to content

Commit

Permalink
Improve alter tablespace syntax rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zihaoAK47 committed Oct 23, 2023
1 parent 5e390f2 commit 3501c01
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ tablespaceName
: identifier
;

newTablespaceName
: identifier
;

subprogramName
: identifier
;
Expand Down Expand Up @@ -1727,6 +1731,10 @@ filenamePattern
: STRING_
;

replacementFilenamePattern
: STRING_
;

connectString
: STRING_
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3922,7 +3922,7 @@ segmentManagementClause
;

tablespaceGroupClause
: TABLESPACE GROUP tablespaceGroupName
: TABLESPACE GROUP (tablespaceGroupName | SQ_ SQ_)
;

temporaryTablespaceClause
Expand Down Expand Up @@ -3957,13 +3957,14 @@ permanentTablespaceClause
;

alterTablespace
: ALTER TABLESPACE tablespaceName
( MINIMUM EXTENT sizeClause
: ALTER TABLESPACE tablespaceName
( defaultTablespaceParams
| MINIMUM EXTENT sizeClause
| RESIZE sizeClause
| COALESCE
| SHRINK SPACE (KEEP sizeClause)?
| RENAME TO newTablespaceName
| (BEGIN|END) BACKUP
| (BEGIN | END) BACKUP
| datafileTempfileClauses
| tablespaceLoggingClauses
| tablespaceGroupClause
Expand All @@ -3973,53 +3974,45 @@ alterTablespace
| tablespaceRetentionClause
| alterTablespaceEncryption
| lostWriteProtection
)
;
)
;

newTablespaceName
: identifier
;
defaultTablespaceParams
: DEFAULT defaultTableCompression? defaultIndexCompression? inmemoryClause? ilmClause? storageClause?
;

datafileTempfileClauses
: ADD (datafileSpecification | tempfileSpecification)
| DROP (DATAFILE | TEMPFILE) (fileSpecification | UNSIGNED_INTEGER) (KEEP sizeClause)?
| SHRINK TEMPFILE (fileSpecification | UNSIGNED_INTEGER) (KEEP sizeClause)?
| RENAME DATAFILE fileSpecification (COMMA_ fileSpecification)* TO fileSpecification (COMMA_ fileSpecification)*
| (DATAFILE | TEMPFILE) (ONLINE|OFFLINE)
;
defaultTableCompression
: TABLE (COMPRESS FOR OLTP | COMPRESS FOR QUERY (LOW | HIGH) | COMPRESS FOR ARCHIVE (LOW | HIGH) | NOCOMPRESS)
;

datafileSpecification
: DATAFILE
(COMMA_? datafileTempfileSpec)
;
defaultIndexCompression
: INDEX (COMPRESS ADVANCED (LOW | HIGH) | NOCOMPRESS)
;

tempfileSpecification
: TEMPFILE
(COMMA_? datafileTempfileSpec)
datafileTempfileClauses
: ADD (DATAFILE | TEMPFILE) (fileSpecification (COMMA_ fileSpecification)*)?
| DROP (DATAFILE | TEMPFILE) (fileName | fileNumber)
| SHRINK TEMPFILE (fileName | fileNumber) (KEEP sizeClause)?
| RENAME DATAFILE fileName (COMMA_ fileName)* TO fileName (COMMA_ fileName)*
| (DATAFILE | TEMPFILE) (ONLINE | OFFLINE)
;

tablespaceLoggingClauses
: loggingClause
| NO? FORCE LOGGING
: loggingClause | NO? FORCE LOGGING
;

tablespaceStateClauses
: ONLINE
| OFFLINE (NORMAL | TEMPORARY | IMMEDIATE)?
| READ (ONLY | WRITE)
| PERMANENT
| TEMPORARY
: ONLINE | OFFLINE (NORMAL | TEMPORARY | IMMEDIATE)? | READ (ONLY | WRITE) | (PERMANENT | TEMPORARY)
;

tablespaceFileNameConvert
: FILE_NAME_CONVERT EQ_ LP_ CHAR_STRING COMMA_ CHAR_STRING (COMMA_ CHAR_STRING COMMA_ CHAR_STRING)* RP_ KEEP?
: FILE_NAME_CONVERT EQ_ LP_ filenamePattern COMMA_ replacementFilenamePattern (COMMA_ filenamePattern COMMA_ replacementFilenamePattern)* RP_ KEEP?
;

alterTablespaceEncryption
: ENCRYPTION ( OFFLINE (tablespaceEncryptionSpec? ENCRYPT | DECRYPT)
| ONLINE (tablespaceEncryptionSpec? (ENCRYPT | REKEY) | DECRYPT) tablespaceFileNameConvert?
| FINISH (ENCRYPT | REKEY | DECRYPT) tablespaceFileNameConvert?
)
: ENCRYPTION(OFFLINE (tablespaceEncryptionSpec? ENCRYPT | DECRYPT)
| ONLINE (tablespaceEncryptionSpec? (ENCRYPT | REKEY) | DECRYPT) tablespaceFileNameConvert?
| FINISH (ENCRYPT | REKEY | DECRYPT) tablespaceFileNameConvert?)
;

dropFunction
Expand Down
4 changes: 4 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/alter-table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,10 @@
<table name="t1" start-index="12" stop-index="13" />
</alter-table>

<alter-table sql-case-id="alter_table_modify_lob_storage_maxsize_cache">
<table name="xml_lob_tab" start-index="12" stop-index="22" />
</alter-table>

<alter-table sql-case-id="alter_table_move_compress_for_oltp">
<table name="table_name" start-index="12" stop-index="21" />
</alter-table>
Expand Down
12 changes: 12 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/alter-tablespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,16 @@
<alter-tablespace sql-case-id="alter_tablespace_autoextend_on_next_g">
<tablespace start-index="17" stop-index="22" name="bigtbs" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_datafile_size_m">
<tablespace start-index="17" stop-index="22" name="lmtbsb" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_nologging">
<tablespace start-index="17" stop-index="22" name="tbs_03" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_tempfile_size_m_reuse">
<tablespace start-index="17" stop-index="22" name="lmtemp" />
</alter-tablespace>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
<sql-case id="alter_table_modify_lob_deduplicate" value="ALTER TABLE t1 MODIFY LOB(a) (DEDUPLICATE)" db-types="Oracle" />
<sql-case id="alter_table_modify_lob_nocompress" value="ALTER TABLE t1 MODIFY LOB(a) (NOCOMPRESS)" db-types="Oracle" />
<sql-case id="alter_table_modify_lob_encrypt_using" value="ALTER TABLE t1 MODIFY LOB(a) (ENCRYPT USING '3DES168')" db-types="Oracle" />
<sql-case id="alter_table_modify_lob_storage_maxsize_cache" value="ALTER TABLE xml_lob_tab MODIFY LOB (XMLDATA) (STORAGE (MAXSIZE 2G) CACHE)" db-types="Oracle" />
<sql-case id="alter_table_move_compress_for_oltp" value="ALTER TABLE table_name MOVE COMPRESS FOR OLTP" db-types="Oracle" />
<sql-case id="alter_table_modify_encrypt_identified_by_password" value="ALTER TABLE t1 MODIFY ( a CLOB ENCRYPT IDENTIFIED BY foo)" db-types="Oracle" />
<sql-case id="alter_table_move_nocompress_parallel" value="ALTER TABLE table_name MOVE NOCOMPRESS PARALLEL" db-types="Oracle" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@
TO '/u02/oracle/rbdb1/users01.dbf',
'/u02/oracle/rbdb1/users02.dbf'" db-types="Oracle" />
<sql-case id="alter_tablespace_autoextend_on_next_g" value="ALTER TABLESPACE bigtbs AUTOEXTEND ON NEXT 20G" db-types="Oracle" />
<sql-case id="alter_tablespace_add_datafile_size_m" value="ALTER TABLESPACE lmtbsb ADD DATAFILE '/u02/oracle/data/lmtbsb02.dbf' SIZE 1M" db-types="Oracle" />
<sql-case id="alter_tablespace_nologging" value="ALTER TABLESPACE tbs_03 NOLOGGING" db-types="Oracle" />
<sql-case id="alter_tablespace_add_tempfile_size_m_reuse" value="ALTER TABLESPACE lmtemp ADD TEMPFILE '/u02/oracle/data/lmtemp02.dbf' SIZE 18M REUSE" db-types="Oracle" />
</sql-cases>

0 comments on commit 3501c01

Please sign in to comment.