@@ -4003,6 +4003,46 @@ void sp_prepare_create_field(THD *thd, Create_field *sql_field)
40034003 (void ) prepare_blob_field (thd, sql_field);
40044004}
40054005
4006+
4007+ /* *
4008+ Auxiliary function which allows to check if freshly created .FRM
4009+ file for table can be opened.
4010+
4011+ @retval FALSE - Success.
4012+ @retval TRUE - Failure.
4013+ */
4014+
4015+ static bool check_if_created_table_can_be_opened (THD *thd,
4016+ const char *path,
4017+ const char *db,
4018+ const char *table_name,
4019+ HA_CREATE_INFO *create_info,
4020+ handler *file)
4021+ {
4022+ TABLE table;
4023+ TABLE_SHARE share;
4024+ bool result;
4025+
4026+ /*
4027+ It is impossible to open definition of partitioned table without .par file.
4028+ */
4029+ if (file->ha_create_handler_files (path, NULL , CHF_CREATE_FLAG, create_info))
4030+ return TRUE ;
4031+
4032+ init_tmp_table_share (thd, &share, db, 0 , table_name, path);
4033+
4034+ result= (open_table_def (thd, &share, 0 ) ||
4035+ open_table_from_share (thd, &share, " " , 0 , (uint) READ_ALL,
4036+ 0 , &table, TRUE ));
4037+ if (! result)
4038+ (void ) closefrm (&table, 0 );
4039+
4040+ free_table_share (&share);
4041+ (void ) file->ha_create_handler_files (path, NULL , CHF_DELETE_FLAG, create_info);
4042+ return result;
4043+ }
4044+
4045+
40064046/*
40074047 Create a table
40084048
@@ -4429,6 +4469,29 @@ bool mysql_create_table_no_lock(THD *thd,
44294469
44304470 thd->thread_specific_used = TRUE ;
44314471 }
4472+ #ifdef WITH_PARTITION_STORAGE_ENGINE
4473+ else if (part_info && create_info->frm_only )
4474+ {
4475+ /*
4476+ For partitioned tables we can't find some problems with table
4477+ until table is opened. Therefore in order to disallow creation
4478+ of corrupted tables we have to try to open table as the part
4479+ of its creation process.
4480+ In cases when both .FRM and SE part of table are created table
4481+ is implicitly open in ha_create_table() call.
4482+ In cases when we create .FRM without SE part we have to open
4483+ table explicitly.
4484+ */
4485+ if (check_if_created_table_can_be_opened (thd, path, db, table_name,
4486+ create_info, file))
4487+ {
4488+ char frm_name[FN_REFLEN];
4489+ strxmov (frm_name, path, reg_ext, NullS);
4490+ (void ) mysql_file_delete (key_file_frm, frm_name, MYF (0 ));
4491+ goto err;
4492+ }
4493+ }
4494+ #endif
44324495
44334496 error= FALSE ;
44344497err:
0 commit comments