Skip to content

fix(meta): disallow replacing tables with different engines - #20234

Open
zhyass wants to merge 2 commits into
databendlabs:mainfrom
zhyass:fix_stats
Open

fix(meta): disallow replacing tables with different engines#20234
zhyass wants to merge 2 commits into
databendlabs:mainfrom
zhyass:fix_stats

Conversation

@zhyass

@zhyass zhyass commented Jul 30, 2026

Copy link
Copy Markdown
Member

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  1. Reject CREATE OR REPLACE when an existing table uses a different engine.
  2. Apply the check to regular tables, streams, atomic CTAS, and temporary tables.
  3. Compare engine names case-insensitively.
  4. Preserve the existing table, stream state, metadata, and data when replacement is rejected.
  5. Add meta API and SQL regression tests for cross-engine replacement and same-engine replacement.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

AI assistance

  • AI usage: An AI coding agent assisted with code analysis, implementation, and test drafting; I reviewed and verified the complete diff.
  • Responsible human: @zhyass
  • The responsible human has read every line of this diff and can explain each change

This change is Reviewable

@github-actions github-actions Bot added the pr-bugfix this PR patches a bug in codebase label Jul 30, 2026

@drmingdrmer drmingdrmer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drmingdrmer reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: 2 of 7 files reviewed, 1 unresolved discussion (waiting on dantengsky, SkyFan2002, TCeason, and zhyass).


src/meta/api/src/api_impl/table_api.rs line 379 at r1 (raw file):

                                if !existing_meta
                                    .engine
                                    .eq_ignore_ascii_case(&req.table_meta.engine)

why is this check done only when as_dropped is set? the codes does not tell the reason behind it.

Code quote:

                            if req.as_dropped {
                                // CTAS does not call construct_drop_table_txn_operations(),
                                // so validate its existing table here.
                                let existing_meta =
                                    self.get_pb(&TableId::new(*id.data)).await?.ok_or_else(|| {
                                        KVAppError::AppError(AppError::UnknownTableId(
                                            UnknownTableId::new(
                                                *id.data,
                                                "create or replace failed to find existing table meta",
                                            ),
                                        ))
                                    })?;
                                if !existing_meta
                                    .engine
                                    .eq_ignore_ascii_case(&req.table_meta.engine)

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

Labels

pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(meta): Disallow creating or replacing same-named tables with different engines

2 participants