| 558 | */ |
| 559 | |
| 560 | static |
| 561 | bool open_and_lock_for_insert_delayed(THD *thd, TABLE_LIST *table_list) |
| 562 | { |
| 563 | MDL_request protection_request; |
| 564 | DBUG_ENTER("open_and_lock_for_insert_delayed"); |
| 565 | |
| 566 | #ifndef EMBEDDED_LIBRARY |
| 567 | /* INSERT DELAYED is not allowed in a read only transaction. */ |
| 568 | if (thd->tx_read_only) |
| 569 | { |
| 570 | my_error(ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION, MYF(0)); |
| 571 | DBUG_RETURN(true); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | In order for the deadlock detector to be able to find any deadlocks |
| 576 | caused by the handler thread waiting for GRL or this table, we acquire |
| 577 | protection against GRL (global IX metadata lock) and metadata lock on |
| 578 | table to being inserted into inside the connection thread. |
| 579 | If this goes ok, the tickets are cloned and added to the list of granted |
| 580 | locks held by the handler thread. |
| 581 | */ |
| 582 | if (thd->has_read_only_protection()) |
| 583 | DBUG_RETURN(TRUE); |
| 584 | |
| 585 | MDL_REQUEST_INIT(&protection_request, MDL_key::BACKUP, "", "", |
| 586 | MDL_BACKUP_DML, MDL_STATEMENT); |
| 587 | |
| 588 | if (thd->mdl_context.acquire_lock(&protection_request, |
| 589 | thd->variables.lock_wait_timeout)) |
| 590 | DBUG_RETURN(TRUE); |
| 591 | |
| 592 | if (thd->mdl_context.acquire_lock(&table_list->mdl_request, |
| 593 | thd->variables.lock_wait_timeout)) |
| 594 | /* |
| 595 | If a lock can't be acquired, it makes no sense to try normal insert. |
| 596 | Therefore we just abort the statement. |
| 597 | */ |
| 598 | DBUG_RETURN(TRUE); |
| 599 | |
| 600 | bool error= FALSE; |
| 601 | if (delayed_get_table(thd, &protection_request, table_list)) |
| 602 | error= TRUE; |
| 603 | else if (table_list->table) |
| 604 | { |
| 605 | /* |
| 606 | Open tables used for sub-selects or in stored functions, will also |
| 607 | cache these functions. |
| 608 | */ |
| 609 | if (table_list->next_global && |
| 610 | open_and_lock_tables(thd, table_list->next_global, TRUE, |
| 611 | MYSQL_OPEN_IGNORE_ENGINE_STATS)) |
| 612 | { |
| 613 | end_delayed_insert(thd); |
| 614 | error= TRUE; |
| 615 | } |
| 616 | else |
| 617 | { |
no test coverage detected