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

Add Replacers.decomposing(): Replacer to decompose a compound statement into equivalent individual statements #13000

Closed
6 tasks done
lukaseder opened this issue Feb 7, 2022 · 2 comments

Comments

@lukaseder
Copy link
Member

lukaseder commented Feb 7, 2022

Some dialects support compound DDL statements, where a single statement changes multiple things atomically. For example:

-- Various dialects support adding multiple columns in one go.
-- There are different syntaxes for this, here's one possible syntax:
ALTER TABLE t
  ADD col1 INT,
  ADD col2 INT

-- MySQL supports adding comments with columns and tables directly:
CREATE TABLE t (
  i INT COMMENT 'column comment'
) COMMENT 'table comment';

It would be useful to be able to decompose a query into multiple queries to result in this:

ALTER TABLE t ADD col1 INT;
ALTER TABLE t ADD col2 INT;

CREATE TABLE t (i INT);
COMMENT ON TABLE t IS 'table comment';
COMMENT ON COLUMN t.i IS 'column comment';

While the original dialect may not be able to run the decomposed queries, the decomposition is still very useful in use-cases like the DDLDatabase, see #12779.

The API of decomposing queries is part of the commercial SQL transformation feature set, but the implementation for this feature should be offered also in the OSS edition to benefit the OSS version of the DDLDatabase.

This feature is part of a bigger task, see #9645

Decompositions implemented so far:

  • MySQL inline column COMMENT to COMMENT ON COLUMN
    • In CREATE TABLE
    • In ALTER TABLE (will be done later)
  • MySQL inline table COMMENT to COMMENT ON TABLE
  • MySQL inline INDEX definition to CREATE INDEX

Decompositions to be considered (perhaps using some configuration, similar to the DDLExportConfiguration)?:

  • Inline constraint specifications to ALTER TABLE .. ADD CONSTRAINT (turned off by default) won't be done for now)

Decompositions that won't be considered:

  • CREATE TABLE .. (col1, col2) to CREATE TABLE .. (col1); ALTER TABLE .. ADD col2

See also:

@lukaseder
Copy link
Member Author

The operation is not very important, so putting it on the ubiquitous Query type generates "API noise". Since it is a SQL transformation, which is best implemented using QueryPart::$replace, it's probably more interesting to place this in a new Replacers type.

@lukaseder lukaseder changed the title Add Query.decompose(): Queries to decompose a compound statement into equivalent individual statements Add Replacers.decompose(): Replacer to decompose a compound statement into equivalent individual statements Feb 7, 2022
@lukaseder lukaseder changed the title Add Replacers.decompose(): Replacer to decompose a compound statement into equivalent individual statements Add Replacers.decomposing(): Replacer to decompose a compound statement into equivalent individual statements Feb 7, 2022
@lukaseder
Copy link
Member Author

This replacer hasn't been too useful so far, but we can re-use it as need arises in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant