[MDEV-5491] CREATE OR REPLACE TABLE Created: 2013-12-27  Updated: 2014-04-22  Due: 2013-12-30  Resolved: 2014-02-11

Status: Closed
Project: MariaDB Server
Component/s: None
Fix Version/s: 10.0.8

Type: Task Priority: Major
Reporter: Michael Widenius Assignee: Michael Widenius
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
PartOf
is part of MDEV-5359 CREATE OR REPLACE, CREATE IF NOT EXIS... Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
MDEV-5516 Server crashes in wait_while_table_is... Technical task Closed Michael Widenius  
MDEV-5517 Assertion `thd->transaction.stmt.is_e... Technical task Closed Michael Widenius  
MDEV-5519 CREATE OR REPLACE TABLE .. LIKE is al... Technical task Closed Michael Widenius  
MDEV-5586 Assertion `share->tdc.all_tables.is_e... Technical task Closed Michael Widenius  
MDEV-5587 Server crashes in Locked_tables_list:... Technical task Closed Michael Widenius  
MDEV-5588 Strange error on CREATE OR REPLACE ta... Technical task Closed Michael Widenius  
MDEV-5589 Discrepancy in binlog on half-failed ... Technical task Closed Michael Widenius  
MDEV-5601 Strange error on CREATE OR REPLACE ..... Technical task Closed Michael Widenius  
MDEV-5602 CREATE OR REPLACE obtains stricter lo... Technical task Closed Michael Widenius  
MDEV-5619 CREATE OR REPLACE does not release MD... Technical task Closed Michael Widenius  
MDEV-5629 Failing assertion: state == TRX_STATE... Technical task Closed Michael Widenius  

 Description   

Implementation of CREATE OR REPLACE TABLE.

This is needed to make replication with GTID work reliable with CREATE ... SELECT.

Using CREATE OR REPLACE TABLE will be identical to

DROP TABLE IF EXISTS table_name;
CREATE TABLE ...;

Except that:

  • The above will be atomic (now one can create the same table between drop and create).
  • Temporary tables will not shadow the table name for the DROP
  • The CREATE TABLE tells us already if we are using a temporary table or not.
  • If this would not be the case, we could with the statement drop a temporary table but still not be able to create the original table.


 Comments   
Comment by Michael Widenius [ 2014-01-09 ]

Now this is almost done, some implementation notes:

  • We don't anymore open the to-be-created table during CREATE TABLE, which the original code did.
  • There is no need to open a table we are planning to create. It's enough to check if the table exists or not.
  • It simplifies CREATE OR REPLACE that we don't open a table we are about to drop and recreate.
  • Removed some of duplicated code for CREATE IF NOT EXISTS.
  • Made OR REPLACE reusable in sql_yacc.yy
  • Both CREATE OR REPLACE TABLE and CREATE OR REPLACE VIEW now uses the same code.
  • An error is given if CREATE OR REPLACE is used for triggers, SP or events (to fixed by another Jira task).
  • Give an error when using CREATE OR REPLACE with IF NOT EXISTS (conflicting options)
  • As a side effect of the code changes, we don't anymore have to internally re-prepare prepared statements with CREATE TABLE if the table exists.
Generated at Thu Feb 08 07:04:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.