| 621 | */ |
| 622 | |
| 623 | int SEQUENCE::read_initial_values(TABLE *table) |
| 624 | { |
| 625 | int error= 0; |
| 626 | enum thr_lock_type save_lock_type; |
| 627 | MDL_request mdl_request; // Empty constructor! |
| 628 | DBUG_ENTER("SEQUENCE::read_initial_values"); |
| 629 | |
| 630 | if (likely(initialized != SEQ_UNINTIALIZED)) |
| 631 | DBUG_RETURN(0); |
| 632 | write_lock(table); |
| 633 | if (likely(initialized == SEQ_UNINTIALIZED)) |
| 634 | { |
| 635 | MYSQL_LOCK *lock; |
| 636 | bool mdl_lock_used= 0; |
| 637 | THD *thd= table->in_use; |
| 638 | bool has_active_transaction= !thd->transaction->stmt.is_empty(); |
| 639 | /* |
| 640 | There is already a mdl_ticket for this table. However, for list_fields |
| 641 | the MDL lock is of type MDL_SHARED_HIGH_PRIO which is not usable |
| 642 | for doing a table lock. Get a proper read lock to solve this. |
| 643 | */ |
| 644 | if (table->mdl_ticket == 0) |
| 645 | { |
| 646 | MDL_request_list mdl_requests; |
| 647 | mdl_lock_used= 1; |
| 648 | /* |
| 649 | This happens if first request is SHOW CREATE TABLE or LIST FIELDS |
| 650 | where we don't have a mdl lock on the table |
| 651 | */ |
| 652 | |
| 653 | MDL_REQUEST_INIT(&mdl_request, MDL_key::TABLE, table->s->db.str, |
| 654 | table->s->table_name.str, MDL_SHARED_READ, |
| 655 | MDL_EXPLICIT); |
| 656 | mdl_requests.push_front(&mdl_request); |
| 657 | if (thd->mdl_context.acquire_locks(&mdl_requests, |
| 658 | thd->variables.lock_wait_timeout)) |
| 659 | { |
| 660 | write_unlock(table); |
| 661 | DBUG_RETURN(HA_ERR_LOCK_WAIT_TIMEOUT); |
| 662 | } |
| 663 | } |
| 664 | save_lock_type= table->reginfo.lock_type; |
| 665 | table->reginfo.lock_type= TL_READ; |
| 666 | if (!(lock= mysql_lock_tables(thd, &table, 1, |
| 667 | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY))) |
| 668 | { |
| 669 | if (mdl_lock_used) |
| 670 | thd->mdl_context.release_lock(mdl_request.ticket); |
| 671 | write_unlock(table); |
| 672 | |
| 673 | if (!has_active_transaction && !thd->transaction->stmt.is_empty() && |
| 674 | !thd->in_sub_stmt) |
| 675 | trans_commit_stmt(thd); |
| 676 | DBUG_RETURN(HA_ERR_LOCK_WAIT_TIMEOUT); |
| 677 | } |
| 678 | DBUG_ASSERT(table->reginfo.lock_type == TL_READ); |
| 679 | if (likely(!(error= read_stored_values(table)))) |
| 680 | initialized= SEQ_READY_TO_USE; |
no test coverage detected