Skip to content

fix: report ALTER TABLE actions that delete rows as MODIFIES_DATA - #2894

Open
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:alter-table-modifies-data
Open

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:alter-table-modifies-data

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

ALTER TABLE t TRUNCATE PARTITION ALL passes the mayModifyData() read-only guard

StatementFeatureVisitor.visit(Alter) returned schema-only for every ALTER TABLE, whatever its actions. TRUNCATE and DROP carry MODIFIES_DATA so that the guard in the docs, if (connection.isReadOnly() && features.mayModifyData()), still stops them (see destructiveDdlAlsoModifiesData), but the ALTER TABLE actions that destroy rows did not: ALTER TABLE t TRUNCATE PARTITION ALL empties a partitioned MySQL table and reported certain=[MODIFIES_SCHEMA], and so did DROP PARTITION, EXCHANGE PARTITION (it swaps the rows of the partition and the other table) and DISCARD / IMPORT TABLESPACE (they delete or replace the table's data file). An action the grammar does not model is kept as raw tokens under AlterOperation.UNSPECIFIC, so ClickHouse's ALTER TABLE t DELETE WHERE 1 = 1 and ALTER TABLE t UPDATE c = 0 WHERE 1 = 1 also gave mayModifyData() == false.

Those partition and tablespace actions now report MODIFIES_DATA as certain, REPAIR PARTITION reports it as possible like REPAIR TABLE does, and an unmodelled action reports it as possible with the unsupported marker, the way an UnsupportedStatement or a CREATE FUNCTION body is treated. Of the 571 ALTER TABLE literals in the test suite, 17 now report MODIFIES_DATA as certain, 39 as possible (35 of them unmodelled actions such as PostgreSQL OWNER TO, SET LOGGED or ENABLE TRIGGER, an over-report on statements that already modify the schema) and 515 are unchanged, so is(..) changes for those 17 only. The 12 new StatementFeatureVisitorTest cases fail before and pass after; ./gradlew check (12439 tests) and mvn verify (12421 tests) pass.

StatementFeatureVisitor classified every ALTER TABLE as schema-only, so
TRUNCATE PARTITION, DROP PARTITION, EXCHANGE PARTITION and DISCARD or
IMPORT TABLESPACE passed a guard checking mayModifyData(), which is the
guard TRUNCATE and DROP carry MODIFIES_DATA for. They now report it as
certain, REPAIR PARTITION as possible like REPAIR TABLE, and an action
the grammar keeps as raw tokens (e.g. ClickHouse ALTER TABLE t DELETE
WHERE ..) as possible with the "unsupported" marker.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant