@@ -362,54 +362,48 @@ where
362362 } ) ;
363363 }
364364 CreateOption :: CreateOrReplace => {
365- if req. as_dropped {
366- // CTAS does not call construct_drop_table_txn_operations(),
367- // so validate its existing table here.
368- let existing_meta =
369- self . get_pb ( & TableId :: new ( * id. data ) ) . await ?. ok_or_else ( || {
370- KVAppError :: AppError ( AppError :: UnknownTableId (
371- UnknownTableId :: new (
372- * id. data ,
373- "create or replace failed to find existing table meta" ,
374- ) ,
375- ) )
376- } ) ?;
377- if !existing_meta
378- . engine
379- . eq_ignore_ascii_case ( & req. table_meta . engine )
380- {
381- return Err ( KVAppError :: AppError (
382- TableEngineMismatch :: new (
383- req. table_name ( ) ,
384- & existing_meta. engine ,
385- & req. table_meta . engine ,
386- )
387- . into ( ) ,
388- ) ) ;
389- }
390-
391- // Guard the engine check against a concurrent metadata update.
392- txn. condition . push ( txn_cond_seq (
393- & TableId :: new ( * id. data ) ,
394- Eq ,
395- existing_meta. seq ,
365+ // CREATE OR REPLACE must not replace an existing table with a
366+ // different engine.
367+ let existing_table_meta = self
368+ . get_pb ( & TableId :: new ( * id. data ) )
369+ . await ?
370+ . ok_or_else ( || {
371+ KVAppError :: AppError ( AppError :: UnknownTableId ( UnknownTableId :: new (
372+ * id. data ,
373+ "create or replace failed to find existing table meta" ,
374+ ) ) )
375+ } ) ?;
376+ if !existing_table_meta
377+ . engine
378+ . eq_ignore_ascii_case ( & req. table_meta . engine )
379+ {
380+ return Err ( KVAppError :: AppError (
381+ TableEngineMismatch :: new (
382+ req. table_name ( ) ,
383+ & existing_table_meta. engine ,
384+ & req. table_meta . engine ,
385+ )
386+ . into ( ) ,
396387 ) ) ;
388+ }
389+
390+ if req. as_dropped {
397391 // If the table is being created as a dropped table, we do not
398392 // need to combine with drop_table_txn operations, just return
399393 // the sequence number associated with the value part of
400394 // the key-value pair (key_dbid_tbname, table_id).
401395
402396 SeqV :: new ( id. seq , * id. data )
403397 } else {
404- // The drop helper validates the engine against the metadata
405- // sequence used by the replacement transaction .
398+ // Reuse the metadata loaded for the engine check when marking the
399+ // existing table as dropped .
406400 let ( seq, id) = construct_drop_table_txn_operations (
407401 self ,
408402 req. name_ident . table_name . clone ( ) ,
409403 & req. name_ident . tenant ,
410404 req. catalog_name . clone ( ) ,
411405 * id. data ,
412- Some ( & req . table_meta . engine ) ,
406+ Some ( existing_table_meta ) ,
413407 * seq_db_id. data ,
414408 true ,
415409 false ,
0 commit comments