Initiates table-file and calls appropriate database-creator. @param thd @param path no extension, e.g. "./test/t1" @param db @param table_name @param create_info @param frm an frm image or NULL (meaning, read it from the file) @param skip_frm_file do not write the frm image to the .frm file @retval 0 ok @retval 1 error */
| 6730 | 1 error |
| 6731 | */ |
| 6732 | int ha_create_table(THD *thd, const char *path, const char *db, |
| 6733 | const char *table_name, HA_CREATE_INFO *create_info, |
| 6734 | LEX_CUSTRING *frm, bool skip_frm_file) |
| 6735 | { |
| 6736 | int error= 1; |
| 6737 | uint ref_length; |
| 6738 | TABLE_SHARE share; |
| 6739 | Abort_on_warning_instant_set old_abort_on_warning(thd, 0); |
| 6740 | bool is_tmp __attribute__((unused)) = |
| 6741 | create_info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER); |
| 6742 | DBUG_ENTER("ha_create_table"); |
| 6743 | |
| 6744 | init_tmp_table_share(thd, &share, db, 0, table_name, path, true); |
| 6745 | |
| 6746 | if (frm) |
| 6747 | { |
| 6748 | bool write_frm_now= (!create_info->db_type->discover_table && |
| 6749 | !create_info->tmp_table() && !skip_frm_file); |
| 6750 | |
| 6751 | share.frm_image= frm; |
| 6752 | |
| 6753 | // open an frm image |
| 6754 | if (share.init_from_binary_frm_image(thd, write_frm_now, |
| 6755 | frm->str, frm->length)) |
| 6756 | goto err; |
| 6757 | } |
| 6758 | else |
| 6759 | { |
| 6760 | // open an frm file |
| 6761 | share.db_plugin= ha_lock_engine(thd, create_info->db_type); |
| 6762 | |
| 6763 | if (open_table_def(thd, &share)) |
| 6764 | goto err; |
| 6765 | } |
| 6766 | |
| 6767 | share.m_psi= PSI_CALL_get_table_share(is_tmp, &share); |
| 6768 | if ((error= ha_create_table_from_share(thd, &share, create_info, &ref_length))) |
| 6769 | { |
| 6770 | PSI_CALL_drop_table_share(is_tmp, share.db.str, (uint)share.db.length, |
| 6771 | share.table_name.str, (uint)share.table_name.length); |
| 6772 | goto err; |
| 6773 | } |
| 6774 | |
| 6775 | /* create secondary tables for high level indexes */ |
| 6776 | if (share.hlindexes()) |
| 6777 | { |
| 6778 | /* as of now: only one vector index can be here */ |
| 6779 | DBUG_ASSERT(share.hlindexes() == 1); |
| 6780 | DBUG_ASSERT(share.key_info[share.keys].algorithm == HA_KEY_ALG_VECTOR); |
| 6781 | TABLE_SHARE index_share; |
| 6782 | char file_name[FN_REFLEN+1]; |
| 6783 | char index_file_name[FN_REFLEN+1], *UNINIT_VAR(index_file_name_end); |
| 6784 | Alter_info index_ainfo; |
| 6785 | HA_CREATE_INFO index_cinfo; |
| 6786 | char *path_end= strmov(file_name, path); |
| 6787 | |
| 6788 | bzero((char*) &index_cinfo, sizeof(index_cinfo)); |
| 6789 | index_cinfo.alter_info= &index_ainfo; |
no test coverage detected