Commit e30e21f0 authored by unknown's avatar unknown

- if table is not transactional, we don't create a transaction

- if table is temporary it's not crash-safe so we declare it
non-transactional (saves trnman calls, REDO/UNDO log writing,
and fixes the assertion failure at the first line of trnman_destroy()).


storage/maria/ha_maria.cc:
  if table is not transactional, no need to create a transaction:
  - it saves trnman calls (mutex locks etc)
  - it saves REDO and UNDO log writing
  - it closes a bug: if this is a temporary table, external_lock(F_RD|WRLCK)
  is not always paired with external_lock(F_UNLCK), which confuses the
  transaction logic in external_lock. As temp tables are not crash-safe
  and so not transactional in this Maria version, we skip transactions
  and de-confuse. Note that maria_lock_database(F_UNLCK) is
  properly called, so if the transaction logic moves from external_lock()
  to maria_lock_database() (probably TODO), transactional temp tables
  will be possible.
storage/maria/ma_create.c:
  temporary tables cannot be crash-safe as they are dropped at restart
storage/maria/maria_def.h:
  comment
parent f5f2a8a1
...@@ -1860,6 +1860,8 @@ int ha_maria::external_lock(THD *thd, int lock_type) ...@@ -1860,6 +1860,8 @@ int ha_maria::external_lock(THD *thd, int lock_type)
{ {
TRN *trn= THD_TRN; TRN *trn= THD_TRN;
DBUG_ENTER("ha_maria::external_lock"); DBUG_ENTER("ha_maria::external_lock");
if (!file->s->base.transactional)
goto skip_transaction;
if (!trn && lock_type != F_UNLCK) /* no transaction yet - open it now */ if (!trn && lock_type != F_UNLCK) /* no transaction yet - open it now */
{ {
trn= trnman_new_trn(& thd->mysys_var->mutex, trn= trnman_new_trn(& thd->mysys_var->mutex,
...@@ -1872,7 +1874,7 @@ int ha_maria::external_lock(THD *thd, int lock_type) ...@@ -1872,7 +1874,7 @@ int ha_maria::external_lock(THD *thd, int lock_type)
DBUG_PRINT("info", ("THD_TRN set to 0x%lx", (ulong)trn)); DBUG_PRINT("info", ("THD_TRN set to 0x%lx", (ulong)trn));
THD_TRN= trn; THD_TRN= trn;
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
trans_register_ha(thd, true, maria_hton); trans_register_ha(thd, TRUE, maria_hton);
} }
if (lock_type != F_UNLCK) if (lock_type != F_UNLCK)
{ {
...@@ -1905,6 +1907,7 @@ int ha_maria::external_lock(THD *thd, int lock_type) ...@@ -1905,6 +1907,7 @@ int ha_maria::external_lock(THD *thd, int lock_type)
} }
} }
} }
skip_transaction:
DBUG_RETURN(maria_lock_database(file, !table->s->tmp_table ? DBUG_RETURN(maria_lock_database(file, !table->s->tmp_table ?
lock_type : ((lock_type == F_UNLCK) ? lock_type : ((lock_type == F_UNLCK) ?
F_UNLCK : F_EXTRA_LCK))); F_UNLCK : F_EXTRA_LCK)));
...@@ -1913,11 +1916,11 @@ int ha_maria::external_lock(THD *thd, int lock_type) ...@@ -1913,11 +1916,11 @@ int ha_maria::external_lock(THD *thd, int lock_type)
int ha_maria::start_stmt(THD *thd, thr_lock_type lock_type) int ha_maria::start_stmt(THD *thd, thr_lock_type lock_type)
{ {
TRN *trn= THD_TRN; TRN *trn= THD_TRN;
DBUG_ASSERT(trn); // this may be called only after external_lock() if (file->s->base.transactional)
DBUG_ASSERT(lock_type != F_UNLCK);
if (!trnman_increment_locked_tables(trn))
{ {
trans_register_ha(thd, false, maria_hton); DBUG_ASSERT(trn); // this may be called only after external_lock()
DBUG_ASSERT(lock_type != F_UNLCK);
/* As external_lock() was already called, don't increment locked_tables */
trnman_new_statement(trn); trnman_new_statement(trn);
} }
return 0; return 0;
......
...@@ -246,6 +246,14 @@ int maria_create(const char *name, enum data_file_type datafile_type, ...@@ -246,6 +246,14 @@ int maria_create(const char *name, enum data_file_type datafile_type,
} }
} }
} }
if (flags & HA_CREATE_TMP_TABLE)
{
options|= HA_OPTION_TMP_TABLE;
create_mode|= O_EXCL | O_NOFOLLOW;
/* temp tables are not crash-safe (dropped at restart) */
ci->transactional= FALSE;
}
share.base.null_bytes= ci->null_bytes; share.base.null_bytes= ci->null_bytes;
share.base.original_null_bytes= ci->null_bytes; share.base.original_null_bytes= ci->null_bytes;
share.base.transactional= ci->transactional; share.base.transactional= ci->transactional;
...@@ -255,11 +263,6 @@ int maria_create(const char *name, enum data_file_type datafile_type, ...@@ -255,11 +263,6 @@ int maria_create(const char *name, enum data_file_type datafile_type,
if (pack_reclength != INT_MAX32) if (pack_reclength != INT_MAX32)
pack_reclength+= max_field_lengths + long_varchar_count; pack_reclength+= max_field_lengths + long_varchar_count;
if (flags & HA_CREATE_TMP_TABLE)
{
options|= HA_OPTION_TMP_TABLE;
create_mode|= O_EXCL | O_NOFOLLOW;
}
if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM)) if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM))
{ {
options|= HA_OPTION_CHECKSUM; options|= HA_OPTION_CHECKSUM;
......
...@@ -168,7 +168,7 @@ typedef struct st_ma_base_info ...@@ -168,7 +168,7 @@ typedef struct st_ma_base_info
/* The following are from the header */ /* The following are from the header */
uint key_parts, all_key_parts; uint key_parts, all_key_parts;
/* If false, we disable logging, versioning etc */ /* If false, we disable logging, versioning, transaction etc */
my_bool transactional; my_bool transactional;
} MARIA_BASE_INFO; } MARIA_BASE_INFO;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment