MCPcopy Create free account
hub / github.com/MariaDB/server / sequence_insert

Function sequence_insert

sql/sql_sequence.cc:462–570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460*/
461
462bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list)
463{
464 int error;
465 TABLE *table;
466 Reprepare_observer *save_reprepare_observer;
467 sequence_definition *seq= lex->create_info.seq_create_info;
468 bool temporary_table= org_table_list->table != 0;
469 /*
470 seq is 0 if sequence was created with CREATE TABLE instead of
471 CREATE SEQUENCE
472 */
473 bool create_new= !seq;
474 Open_tables_backup open_tables_backup;
475 Query_tables_list query_tables_list_backup;
476 TABLE_LIST table_list; // For sequence table
477 DBUG_ENTER("sequence_insert");
478 DBUG_EXECUTE_IF("kill_query_on_sequence_insert",
479 thd->set_killed(KILL_QUERY););
480
481 if (create_new && !(seq= new (thd->mem_root) sequence_definition))
482 DBUG_RETURN(TRUE);
483
484 /* If not temporary table */
485 if (!temporary_table)
486 {
487 /*
488 The following code works like open_system_tables_for_read()
489 The idea is:
490 - Copy the table_list object for the sequence that was created
491 - Backup the current state of open tables and create a new
492 environment for open tables without any tables opened
493 - open the newly sequence table for write
494 This is safe as the sequence table has a mdl lock thanks to the
495 create sequence statement that is calling this function
496 */
497
498 table_list.init_one_table(&org_table_list->db,
499 &org_table_list->table_name,
500 NULL, TL_WRITE_DEFAULT);
501 table_list.updating= 1;
502 table_list.open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
503 table_list.open_type= OT_BASE_ONLY;
504
505 DBUG_ASSERT(!thd->locked_tables_mode ||
506 (thd->variables.option_bits & OPTION_TABLE_LOCK));
507 lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
508 thd->reset_n_backup_open_tables_state(&open_tables_backup);
509
510 /*
511 The FOR CREATE flag is needed to ensure that ha_open() doesn't try to
512 read the not yet existing row in the sequence table
513 */
514 thd->open_options|= HA_OPEN_FOR_CREATE;
515 /*
516 We have to reset the reprepare observer to be able to open the
517 table under prepared statements.
518 */
519 save_reprepare_observer= thd->m_reprepare_observer;

Callers 1

Calls 14

trans_commit_stmtFunction · 0.85
trans_commit_implicitFunction · 0.85
close_thread_tablesFunction · 0.85
set_killedMethod · 0.80
init_one_tableMethod · 0.80
check_and_adjustMethod · 0.80
open_and_lock_tablesFunction · 0.70

Tested by

no test coverage detected