fix an old bug where dd_frm_type() could incorrectly determine the table type
for dynamic engines (because it only looked at the one-byte code, not at the full engine name).
This commit is contained in:
parent
68325b6a12
commit
28a9fea122
12
mysql-test/r/drop_bad_db_type.result
Normal file
12
mysql-test/r/drop_bad_db_type.result
Normal file
@ -0,0 +1,12 @@
|
||||
set debug_dbug='+d,unstable_db_type';
|
||||
install soname 'ha_archive';
|
||||
create table t1 (a int) engine=archive;
|
||||
insert t1 values (1),(2),(3);
|
||||
flush tables;
|
||||
uninstall soname 'ha_archive';
|
||||
install soname 'ha_archive';
|
||||
t1.ARZ
|
||||
t1.frm
|
||||
drop table t1;
|
||||
uninstall soname 'ha_archive';
|
||||
set debug_dbug='-d,unstable_db_type';
|
25
mysql-test/t/drop_bad_db_type.test
Normal file
25
mysql-test/t/drop_bad_db_type.test
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
--source include/have_debug.inc
|
||||
|
||||
if (!$HA_ARCHIVE_SO) {
|
||||
skip Needs Archive plugin;
|
||||
}
|
||||
|
||||
let $mysqld_datadir= `select @@datadir`;
|
||||
|
||||
set debug_dbug='+d,unstable_db_type';
|
||||
|
||||
install soname 'ha_archive';
|
||||
create table t1 (a int) engine=archive;
|
||||
insert t1 values (1),(2),(3);
|
||||
flush tables;
|
||||
uninstall soname 'ha_archive';
|
||||
|
||||
install soname 'ha_archive';
|
||||
--list_files $mysqld_datadir/test
|
||||
drop table t1;
|
||||
--list_files $mysqld_datadir/test
|
||||
uninstall soname 'ha_archive';
|
||||
|
||||
set debug_dbug='-d,unstable_db_type';
|
||||
|
@ -6,6 +6,8 @@
|
||||
drop table if exists t1,t2;
|
||||
--enable_warnings
|
||||
|
||||
let $mysqld_datadir= `select @@datadir`;
|
||||
|
||||
set names latin1;
|
||||
|
||||
select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
|
||||
@ -1385,6 +1387,8 @@ LOAD DATA INFILE 'bug58165.txt' INTO TABLE t1;
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
--remove_file $mysqld_datadir/test/bug58165.txt
|
||||
|
||||
#
|
||||
# MDEV-759 lp:998340 - Valgrind complains on simple selects containing expression DAY(FROM_UNIXTIME(-1))
|
||||
#
|
||||
|
@ -36,6 +36,7 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
|
||||
File file;
|
||||
uchar header[10]; //"TYPE=VIEW\n" it is 10 characters
|
||||
size_t error;
|
||||
frm_type_enum type= FRMTYPE_ERROR;
|
||||
DBUG_ENTER("dd_frm_type");
|
||||
|
||||
*dbt= DB_TYPE_UNKNOWN;
|
||||
@ -43,12 +44,16 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
|
||||
if ((file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0))) < 0)
|
||||
DBUG_RETURN(FRMTYPE_ERROR);
|
||||
error= mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP));
|
||||
mysql_file_close(file, MYF(MY_WME));
|
||||
|
||||
if (error)
|
||||
DBUG_RETURN(FRMTYPE_ERROR);
|
||||
goto err;
|
||||
if (!strncmp((char*) header, "TYPE=VIEW\n", sizeof(header)))
|
||||
DBUG_RETURN(FRMTYPE_VIEW);
|
||||
{
|
||||
type= FRMTYPE_VIEW;
|
||||
goto err;
|
||||
}
|
||||
|
||||
type= FRMTYPE_TABLE;
|
||||
|
||||
/*
|
||||
This is just a check for DB_TYPE. We'll return default unknown type
|
||||
@ -58,12 +63,57 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
|
||||
if (header[0] != (uchar) 254 || header[1] != 1 ||
|
||||
(header[2] != FRM_VER && header[2] != FRM_VER+1 &&
|
||||
(header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
|
||||
DBUG_RETURN(FRMTYPE_TABLE);
|
||||
goto err;
|
||||
|
||||
*dbt= (enum legacy_db_type) (uint) *(header + 3);
|
||||
|
||||
if (*dbt >= DB_TYPE_FIRST_DYNAMIC) /* read the true engine name */
|
||||
{
|
||||
MY_STAT state;
|
||||
uchar *frm_image= 0;
|
||||
uint n_length;
|
||||
|
||||
if (mysql_file_fstat(file, &state, MYF(MY_WME)))
|
||||
goto err;
|
||||
|
||||
if (mysql_file_seek(file, 0, SEEK_SET, MYF(MY_WME)))
|
||||
goto err;
|
||||
|
||||
if (read_string(file, &frm_image, state.st_size))
|
||||
goto err;
|
||||
|
||||
if ((n_length= uint4korr(frm_image+55)))
|
||||
{
|
||||
uint record_offset= (uint2korr(frm_image+6)+
|
||||
((uint2korr(frm_image+14) == 0xffff ?
|
||||
uint4korr(frm_image+47) : uint2korr(frm_image+14))));
|
||||
uint reclength= uint2korr(frm_image+16);
|
||||
|
||||
uchar *next_chunk= frm_image + record_offset + reclength;
|
||||
uchar *buff_end= next_chunk + n_length;
|
||||
uint connect_string_length= uint2korr(next_chunk);
|
||||
next_chunk+= connect_string_length + 2;
|
||||
if (next_chunk + 2 < buff_end)
|
||||
{
|
||||
uint str_db_type_length= uint2korr(next_chunk);
|
||||
LEX_STRING name;
|
||||
name.str= (char*) next_chunk + 2;
|
||||
name.length= str_db_type_length;
|
||||
plugin_ref tmp_plugin= ha_resolve_by_name(thd, &name);
|
||||
if (tmp_plugin)
|
||||
*dbt= plugin_data(tmp_plugin, handlerton *)->db_type;
|
||||
else
|
||||
*dbt= DB_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
my_free(frm_image);
|
||||
}
|
||||
|
||||
/* Probably a table. */
|
||||
DBUG_RETURN(FRMTYPE_TABLE);
|
||||
err:
|
||||
mysql_file_close(file, MYF(MY_WME));
|
||||
DBUG_RETURN(type);
|
||||
}
|
||||
|
||||
|
||||
|
@ -486,6 +486,12 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
|
||||
{
|
||||
uint tmp;
|
||||
ulong fslot;
|
||||
|
||||
DBUG_EXECUTE_IF("unstable_db_type", {
|
||||
static int i= (int) DB_TYPE_FIRST_DYNAMIC;
|
||||
hton->db_type= (enum legacy_db_type)++i;
|
||||
});
|
||||
|
||||
/* now check the db_type for conflict */
|
||||
if (hton->db_type <= DB_TYPE_UNKNOWN ||
|
||||
hton->db_type >= DB_TYPE_DEFAULT ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user