Skip to content

Commit

Permalink
MDEV-6916 REPAIR VIEW / mysql migration
Browse files Browse the repository at this point in the history
from: r4407
  • Loading branch information
Oleksandr Byelkin authored and grooverdan committed Apr 12, 2015
1 parent e5191dd commit c8dbef2
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 27 deletions.
1 change: 1 addition & 0 deletions include/myisamchk.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#define TT_USEFRM 1
#define TT_FOR_UPGRADE 2
#define TT_FROM_MYSQL 4

/* Bits set in out_flag */
#define O_NEW_DATA 2
Expand Down
2 changes: 2 additions & 0 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

// the following is for checking tables

#define HA_ADMIN_VIEW_REPAIR_IS_DONE 2
#define HA_ADMIN_ALREADY_DONE 1
#define HA_ADMIN_OK 0
#define HA_ADMIN_NOT_IMPLEMENTED -1
Expand All @@ -56,6 +57,7 @@
#define HA_ADMIN_NEEDS_UPGRADE -10
#define HA_ADMIN_NEEDS_ALTER -11
#define HA_ADMIN_NEEDS_CHECK -12
#define HA_ADMIN_NEEDS_REPAIR -13

/* Bits in table_flags() to show what database can do */

Expand Down
1 change: 1 addition & 0 deletions sql/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ static SYMBOL symbols[] = {
{ "MULTIPOINT", SYM(MULTIPOINT)},
{ "MULTIPOLYGON", SYM(MULTIPOLYGON)},
{ "MUTEX", SYM(MUTEX_SYM)},
{ "MYSQL", SYM(MYSQL_SYM)},
{ "MYSQL_ERRNO", SYM(MYSQL_ERRNO_SYM)},
{ "NAME", SYM(NAME_SYM)},
{ "NAMES", SYM(NAMES_SYM)},
Expand Down
6 changes: 6 additions & 0 deletions sql/share/errmsg-utf8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6565,3 +6565,9 @@ ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT
ER_NO_SUCH_TABLE_IN_ENGINE 42S02
eng "Table '%-.192s.%-.192s' doesn't exist in engine"
swe "Det finns ingen tabell som heter '%-.192s.%-.192s' i handlern"
ER_NO_MARIADB_SERVER_FIELD
eng "view '%-.192s.%-.192s' has no field mariadb server in its .frm file"
ER_VIEW_REPAIR_IS_DONE
eng "view is repaired"
ER_NEEDS_REPAIR
eng "needs repair"
44 changes: 36 additions & 8 deletions sql/sql_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
HA_CHECK_OPT *),
int (handler::*operator_func)(THD *,
HA_CHECK_OPT *),
int (view_operator_func)(THD *, TABLE_LIST*))
int (view_operator_func)(THD *, TABLE_LIST*,
HA_CHECK_OPT *))
{
TABLE_LIST *table;
SELECT_LEX *select= &thd->lex->select_lex;
Expand Down Expand Up @@ -380,7 +381,18 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
lex->query_tables_own_last= 0;

if (view_operator_func == NULL)
{
table->required_type=FRMTYPE_TABLE;
DBUG_ASSERT(!lex->only_view);
}
else if (lex->only_view)
{
table->required_type= FRMTYPE_VIEW;
}
else if (!lex->only_view && lex->sql_command == SQLCOM_REPAIR)
{
table->required_type= FRMTYPE_TABLE;
}

if (lex->sql_command == SQLCOM_CHECK ||
lex->sql_command == SQLCOM_REPAIR ||
Expand Down Expand Up @@ -506,9 +518,9 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
}

/*
CHECK TABLE command is only command where VIEW allowed here and this
command use only temporary teble method for VIEWs resolving => there
can't be VIEW tree substitition of join view => if opening table
CHECK/REPAIR TABLE command is only command where VIEW allowed here and
this command use only temporary table method for VIEWs resolving =>
there can't be VIEW tree substitition of join view => if opening table
succeed then table->table will have real TABLE pointer as value (in
case of join view substitution table->table can be 0, but here it is
impossible)
Expand All @@ -521,7 +533,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
ER_CHECK_NO_SUCH_TABLE, ER(ER_CHECK_NO_SUCH_TABLE));
/* if it was a view will check md5 sum */
if (table->view &&
view_checksum(thd, table) == HA_ADMIN_WRONG_CHECKSUM)
view_check(thd, table, check_opt) == HA_ADMIN_WRONG_CHECKSUM)
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_VIEW_CHECKSUM, ER(ER_VIEW_CHECKSUM));
if (thd->stmt_da->is_error() &&
Expand All @@ -536,7 +548,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (table->view)
{
DBUG_PRINT("admin", ("calling view_operator_func"));
result_code= (*view_operator_func)(thd, table);
result_code= (*view_operator_func)(thd, table, check_opt);
goto send_result;
}

Expand Down Expand Up @@ -867,6 +879,22 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
fatal_error=1;
break;
}
case HA_ADMIN_VIEW_REPAIR_IS_DONE:
{
protocol->store(STRING_WITH_LEN("status"), system_charset_info);
protocol->store(ER(ER_VIEW_REPAIR_IS_DONE),
strlen(ER(ER_VIEW_REPAIR_IS_DONE)),
system_charset_info);
break;
}
case HA_ADMIN_NEEDS_REPAIR:
{
protocol->store(STRING_WITH_LEN("status"), system_charset_info);
protocol->store(ER(ER_NEEDS_REPAIR),
strlen(ER(ER_NEEDS_REPAIR)),
system_charset_info);
break;
}

default: // Probably HA_ADMIN_INTERNAL_ERROR
{
Expand Down Expand Up @@ -1071,7 +1099,7 @@ bool Check_table_statement::execute(THD *thd)

res= mysql_admin_table(thd, first_table, &m_lex->check_opt, "check",
lock_type, 0, 0, HA_OPEN_FOR_REPAIR, 0,
&handler::ha_check, &view_checksum);
&handler::ha_check, &view_check);

m_lex->select_lex.table_list.first= first_table;
m_lex->query_tables= first_table;
Expand Down Expand Up @@ -1126,7 +1154,7 @@ bool Repair_table_statement::execute(THD *thd)
TL_WRITE, 1,
test(m_lex->check_opt.sql_flags & TT_USEFRM),
HA_OPEN_FOR_REPAIR, &prepare_for_repair,
&handler::ha_repair, 0);
&handler::ha_repair, &view_repair);

/* ! we write after unlocking the table */
if (!res && !m_lex->no_write_to_binlog)
Expand Down
10 changes: 8 additions & 2 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
open_table_error(share, share->error, share->open_errno, share->errarg);
DBUG_RETURN(0);
}
if (share->is_view && !(db_flags & OPEN_VIEW))
if ((share->is_view && !(db_flags & OPEN_VIEW)) ||
(!share->is_view && (db_flags & OPEN_VIEW_ONLY)))
{
open_table_error(share, 1, ENOENT, 0);
DBUG_RETURN(0);
Expand Down Expand Up @@ -3022,12 +3023,17 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB)
DBUG_RETURN(FALSE);


retry_share:

mysql_mutex_lock(&LOCK_open);

if (!(share= get_table_share_with_discover(thd, table_list, key,
key_length, OPEN_VIEW,
key_length,
(OPEN_VIEW |
((table_list->required_type ==
FRMTYPE_VIEW) ?
OPEN_VIEW_ONLY : 0)),
&error,
hash_value)))
{
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "sql_base.h" // open_table_uncached, lock_table_names
#include "lock.h" // mysql_unlock_tables
#include "strfunc.h" // find_type2, find_set
#include "sql_view.h" // view_checksum
#include "sql_view.h" // view_check
#include "sql_truncate.h" // regenerate_locked_table
#include "sql_partition.h" // mem_alloc_error,
// generate_partition_syntax,
Expand Down
Loading

0 comments on commit c8dbef2

Please sign in to comment.