WL#8657: True bottom-up server parser: refactoring of the ALTER TABLE statement

Affects: Server-8.0   —   Status: Complete

This WL is intended to refactor ALTER TABLE|VIEW statement-related parser grammar rules in a pure bottom-up style to make it (grammar) context-independent for the better maintainability and extendability at the first place.

User Documentation

Functional requirements

  • F1-1: See minor changes in the "Changes in the behaviour" paragraph in the HLS.

Non-functional requirements

  • NF-1: Apart from the changes mentioned in the "Changes in the behaviour" paragraph in the HLS, there shall be no changes visible to users.
  • NF-2: No performance regressions.

Changes in behavior

This is a parser refactoring WL, but it also introduces a few changes in the behavior:

1. The bugfix for line numbers in error messages:

  • Before the WL, if the IGNORE_SPACE flags was on, syntax error message always pointed to a wrong (first) line. The current WL fixes that.

2. Removal of the non-standard redundant undocumented syntax: 2D and 3D column names in CREATE/ALTER TABLE statements.

  • The parser accepted a redundant syntax:

 USE schema1;
 CREATE TABLE table1 (table1.column1... schema1.table1.column2 ...
 ALTER TABLE table1 ... table1.column1... schema1.table1.column2 ...
  • Note table1.column1 and schema1.table1.column2, where the current table is schema1.table1.
  • And there was a check if table1.column1 and schema1.table1.column2 belong to schema1.table1. So, nothing but current table name and schema can happen there.
  • That syntax was discussed long time ago (the discussion doesn't seem to be finished) in the context of BUG#10413, where the check was added initially.
  • The current WL removes that syntax.
  • The removal helps to save two shift/reduce conflicts and skip redundant checks.
  • As a side-effect, the current WL removes the "ODBC" or "Delphi" (as in source code comments) for the .column syntax (the removal is approved in the context of the next WL#8662).

List of refactored statements

  • ALTER TABLE
  • ANALYZE TABLE
  • CACHE INDEX
  • CHECK TABLE
  • CREATE INDEX (some minor cleanup)
  • CREATE TABLE (some cleanup after WL#8067)
  • DROP INDEX
  • LOAD INDEX
  • OPTIMIZE TABLE
  • REPAIR TABLE
  • TRUNCATE (was tangled with ALTER TABLE internals -- now untangled)

Contents


Ideas

The sub-goal of the current chunk of work is the isolation of the Alter_info structure outside parse tree and Sql_cmd code as much as possible.

The goal is 90% achieved by the current WL:

  • We still have a minimal direct access to LEX::alter_info from only a few places in the server.
  • The WL replaces LEX::alter_info structure with a pointer -- the parser allocates it in the parse tree code, then passes the pointer to Alter_info into LEX and Sql_cmd simultaneously.

Changes in AST

Changes in LEX: removal of intermediate/redundant values and functions

  • drop_mode
  • is_partition_management() -- moved to the parse tree

Changes in the parse tree: new classes

Class name Description
Parse_tree_top A contextualize()-less replacement for PT_statement
PT_table_ddl_stmt_base A base class for table DDL statement nodes
PT_create_table_option A base class for all CREATE TABLE clauses
PT_alter_table_stmt A root node for the regular (multi-action) ALTER TABLE statement
PT_alter_table_standalone_stmt A root node of all "standalone" (single-action) ALTER TABLE statements
PT_repair_table_stmt REPAIR TABLE statement
PT_analyze_table_stmt ANALYZE TABLE statement
PT_check_table_stmt CHECK TABLE statement
PT_optimize_table_stmt OPTIMIZE TABLE statement
PT_drop_index_stmt DROP INDEX statement
PT_truncate_table_stmt TRUNCATE TABLE statement
PT_cache_index_stmt CACHE INDEX statement
PT_cache_index_partitions_stmt CACHE INDEX ... PARTITION statement
PT_load_index_stmt LOAD INDEX statement
PT_load_index_partitions_stmt LOAD INDEX ... PARTITION statement

ALTER TABLE actions

Class name Description
PT_alter_table_action A base class for all ALTER TABLE clauses
PT_alter_table_add_column A single-column ADD COLUMN clause
PT_alter_table_add_columns A multi-column ADD COLUMN
PT_alter_table_add_constraint Index-related clauses
PT_alter_table_change_column CHANGE COLUMN clause
PT_alter_table_drop A base node for all DROP clauses
PT_alter_table_drop_foreign_key DROP FOREIGN KEY clause
PT_alter_table_drop_key DROP KEY clause
PT_alter_table_enable_keys ENABLE KEYS clause
PT_alter_table_set_default SET DEFAULT clause
PT_alter_table_index_visible INDEX VISIBLE clause
PT_alter_table_rename RENAME table clause
PT_alter_table_rename_key RENAME KEY clause
PT_alter_table_convert_to_charset CONVERT TO CHARSET clause
PT_alter_table_force FORCE clause
PT_alter_table_order ORDER clause
PT_alter_table_partition_by PARTITION BY clause
PT_alter_table_remove_partitioning REMOVE PARTITIONING clause
PT_alter_table_standalone_action base class for a group of standalone ALTER TABLE actions
PT_alter_table_add_partition ALTER TABLE ... ADD PARTITION
PT_alter_table_add_partition_def_list ALTER TABLE ... ADD PARTITION ... (<list>)
PT_alter_table_add_partition_num ALTER TABLE ... ADD PARTITION PARTITIONS (<number>)
PT_alter_table_drop_partition ALTER TABLE ... DROP PARTITION
PT_alter_table_partition_list_or_all A base class for partition-related statements with the ALL clause
PT_alter_table_rebuild_partition ALTER TABLE ... REBUILD PARTITION
PT_alter_table_optimize_partition ALTER TABLE ... OPTIMIZE PARTITION
PT_alter_table_analyze_partition ALTER TABLE ... ANALYZE PARTITION
PT_alter_table_check_partition ALTER TABLE ... CHECK PARTITION
PT_alter_table_repair_partition ALTER TABLE ... REPAIR PARTITION
PT_alter_table_coalesce_partition ALTER TABLE ... COALESCE PARTITION
PT_alter_table_truncate_partition ALTER TABLE ... TRUNCATE PARTITION
PT_alter_table_reorganize_partition ALTER TABLE ... REORGANIZE PARTITION
PT_alter_table_reorganize_partition_into ALTER TABLE ... REORGANIZE PARTITION INTO
PT_alter_table_exchange_partition ALTER TABLE ... EXCHANGE PARTITION
PT_alter_table_discard_partition_tablespace ALTER TABLE ... DISCARD PARTITION TABLESPACE
PT_alter_table_import_partition_tablespace ALTER TABLE ... IMPORT PARTITION TABLESPACE
PT_alter_table_discard_tablespace ALTER TABLE ... DISCARD TABLESPACE
PT_alter_table_import_tablespace ALTER TABLE ... IMPORT TABLESPACE

Other stuff

Class name Description
PT_assign_to_keycache Cache name list of the CACHE INDEX statement
PT_adm_partition PARTITION clause of the CACHE INDEX statement
PT_preload_keys Cache list of the LOAD INDEX statement