Commit 68d26515 authored by unknown's avatar unknown

Merge sunlight.local:/local_work/leak_fix_orig

into  sunlight.local:/local_work/leak_fix-5.1-mysql


sql/sql_lex.h:
  Auto merged
sql/sql_view.cc:
  Auto merged
sql/sql_view.h:
  Auto merged
sql/unireg.h:
  Auto merged
sql/sql_base.cc:
  Manual merge
sql/table.cc:
  Manual merge
parents b6897efb 1e9ebd01
...@@ -39,7 +39,7 @@ static bool table_def_inited= 0; ...@@ -39,7 +39,7 @@ static bool table_def_inited= 0;
static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list, static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
const char *alias, const char *alias,
char *cache_key, uint cache_key_length, char *cache_key, uint cache_key_length,
MEM_ROOT *mem_root); MEM_ROOT *mem_root, uint flags);
static void free_cache_entry(TABLE *entry); static void free_cache_entry(TABLE *entry);
static void mysql_rm_tmp_tables(void); static void mysql_rm_tmp_tables(void);
static bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias, static bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
...@@ -1763,7 +1763,7 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) ...@@ -1763,7 +1763,7 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
if (open_unireg_entry(thd, table, table_list, table_name, if (open_unireg_entry(thd, table, table_list, table_name,
table->s->table_cache_key.str, table->s->table_cache_key.str,
table->s->table_cache_key.length, thd->mem_root)) table->s->table_cache_key.length, thd->mem_root, 0))
{ {
intern_close_table(table); intern_close_table(table);
/* /*
...@@ -1960,7 +1960,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, ...@@ -1960,7 +1960,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table= &tab; table= &tab;
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
if (!open_unireg_entry(thd, table, table_list, alias, if (!open_unireg_entry(thd, table, table_list, alias,
key, key_length, mem_root)) key, key_length, mem_root, 0))
{ {
DBUG_ASSERT(table_list->view != 0); DBUG_ASSERT(table_list->view != 0);
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
...@@ -2044,6 +2044,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, ...@@ -2044,6 +2044,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
} }
else else
{ {
int error;
/* Free cache if too big */ /* Free cache if too big */
while (open_cache.records > table_cache_size && unused_tables) while (open_cache.records > table_cache_size && unused_tables)
VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */ VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */
...@@ -2055,15 +2056,23 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, ...@@ -2055,15 +2056,23 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
if (open_unireg_entry(thd, table, table_list, alias, key, key_length, error= open_unireg_entry(thd, table, table_list, alias, key, key_length,
mem_root)) mem_root, (flags & OPEN_VIEW_NO_PARSE));
if (error > 0)
{ {
my_free((gptr)table, MYF(0)); my_free((gptr)table, MYF(0));
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
if (table_list->view) if (table_list->view || error < 0)
{ {
/*
VIEW not really opened, only frm were read.
Set 1 as a flag here
*/
if (error < 0)
table_list->view= (st_lex*)1;
my_free((gptr)table, MYF(0)); my_free((gptr)table, MYF(0));
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_RETURN(0); // VIEW DBUG_RETURN(0); // VIEW
...@@ -2165,7 +2174,6 @@ static bool reopen_table(TABLE *table) ...@@ -2165,7 +2174,6 @@ static bool reopen_table(TABLE *table)
sql_print_error("Table %s had a open data handler in reopen_table", sql_print_error("Table %s had a open data handler in reopen_table",
table->alias); table->alias);
#endif #endif
table_list.db= table->s->db.str; table_list.db= table->s->db.str;
table_list.table_name= table->s->table_name.str; table_list.table_name= table->s->table_name.str;
table_list.table= table; table_list.table= table;
...@@ -2179,7 +2187,7 @@ static bool reopen_table(TABLE *table) ...@@ -2179,7 +2187,7 @@ static bool reopen_table(TABLE *table)
table->alias, table->alias,
table->s->table_cache_key.str, table->s->table_cache_key.str,
table->s->table_cache_key.length, table->s->table_cache_key.length,
thd->mem_root)) thd->mem_root, 0))
goto end; goto end;
/* This list copies variables set by open_table */ /* This list copies variables set by open_table */
...@@ -2613,6 +2621,8 @@ void assign_new_table_id(TABLE_SHARE *share) ...@@ -2613,6 +2621,8 @@ void assign_new_table_id(TABLE_SHARE *share)
cache_key Key for share_cache cache_key Key for share_cache
cache_key_length length of cache_key cache_key_length length of cache_key
mem_root temporary mem_root for parsing mem_root temporary mem_root for parsing
flags the OPEN_VIEW_NO_PARSE flag to be passed to
openfrm()/open_new_frm()
NOTES NOTES
Extra argument for open is taken from thd->open_options Extra argument for open is taken from thd->open_options
...@@ -2626,7 +2636,7 @@ void assign_new_table_id(TABLE_SHARE *share) ...@@ -2626,7 +2636,7 @@ void assign_new_table_id(TABLE_SHARE *share)
static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list, static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
const char *alias, const char *alias,
char *cache_key, uint cache_key_length, char *cache_key, uint cache_key_length,
MEM_ROOT *mem_root) MEM_ROOT *mem_root, uint flags)
{ {
int error; int error;
TABLE_SHARE *share; TABLE_SHARE *share;
...@@ -2649,7 +2659,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list, ...@@ -2649,7 +2659,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
HA_GET_INDEX | HA_TRY_READ_ONLY), HA_GET_INDEX | HA_TRY_READ_ONLY),
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
thd->open_options, entry, table_list, thd->open_options, entry, table_list,
mem_root); mem_root, (flags & OPEN_VIEW_NO_PARSE)));
if (error) if (error)
goto err; goto err;
/* TODO: Don't free this */ /* TODO: Don't free this */
...@@ -2707,7 +2717,6 @@ static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list, ...@@ -2707,7 +2717,6 @@ static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
} }
if (!entry->s || !entry->s->crashed) if (!entry->s || !entry->s->crashed)
goto err; goto err;
// Code below is for repairing a crashed file // Code below is for repairing a crashed file
if ((error= lock_table_name(thd, table_list, TRUE))) if ((error= lock_table_name(thd, table_list, TRUE)))
{ {
...@@ -6339,7 +6348,8 @@ open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias, ...@@ -6339,7 +6348,8 @@ open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
"BASE TABLE"); "BASE TABLE");
goto err; goto err;
} }
if (mysql_make_view(thd, parser, table_desc)) if (mysql_make_view(thd, parser, table_desc,
(prgflag & OPEN_VIEW_NO_PARSE)))
goto err; goto err;
} }
else else
......
...@@ -402,7 +402,7 @@ class st_select_lex_node { ...@@ -402,7 +402,7 @@ class st_select_lex_node {
friend class st_select_lex_unit; friend class st_select_lex_unit;
friend bool mysql_new_select(struct st_lex *lex, bool move_down); friend bool mysql_new_select(struct st_lex *lex, bool move_down);
friend bool mysql_make_view(THD *thd, File_parser *parser, friend bool mysql_make_view(THD *thd, File_parser *parser,
TABLE_LIST *table); TABLE_LIST *table, uint flags);
private: private:
void fast_exclude(); void fast_exclude();
}; };
......
...@@ -183,7 +183,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view) ...@@ -183,7 +183,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view)
TABLE_LIST decoy; TABLE_LIST decoy;
memcpy (&decoy, view, sizeof (TABLE_LIST)); memcpy (&decoy, view, sizeof (TABLE_LIST));
if (!open_table(thd, &decoy, thd->mem_root, &not_used, 0) && if (!open_table(thd, &decoy, thd->mem_root, &not_used, OPEN_VIEW_NO_PARSE) &&
!decoy.view) !decoy.view)
{ {
return TRUE; return TRUE;
...@@ -817,13 +817,14 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -817,13 +817,14 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
thd Thread handler thd Thread handler
parser parser object parser parser object
table TABLE_LIST structure for filling table TABLE_LIST structure for filling
flags flags
RETURN RETURN
0 ok 0 ok
1 error 1 error
*/ */
bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
uint flags)
{ {
SELECT_LEX *end, *view_select; SELECT_LEX *end, *view_select;
LEX *old_lex, *lex; LEX *old_lex, *lex;
...@@ -914,6 +915,10 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) ...@@ -914,6 +915,10 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table)
table->db, table->table_name); table->db, table->table_name);
get_default_definer(thd, &table->definer); get_default_definer(thd, &table->definer);
} }
if (flags & OPEN_VIEW_NO_PARSE)
{
DBUG_RETURN(FALSE);
}
/* /*
Save VIEW parameters, which will be wiped out by derived table Save VIEW parameters, which will be wiped out by derived table
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
bool mysql_create_view(THD *thd, bool mysql_create_view(THD *thd,
enum_view_create_mode mode); enum_view_create_mode mode);
bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table); bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
uint flags);
bool mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode); bool mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode);
......
...@@ -353,6 +353,9 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) ...@@ -353,6 +353,9 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags)
else else
goto err; goto err;
if (prgflag & OPEN_VIEW_NO_PARSE)
goto err;
/* No handling of text based files yet */ /* No handling of text based files yet */
if (table_type == 1) if (table_type == 1)
{ {
......
...@@ -151,7 +151,8 @@ ...@@ -151,7 +151,8 @@
#define READ_SCREENS 1024 /* Read screens, info and helpfile */ #define READ_SCREENS 1024 /* Read screens, info and helpfile */
#define DELAYED_OPEN 4096 /* Open table later */ #define DELAYED_OPEN 4096 /* Open table later */
#define OPEN_VIEW 8192 /* Allow open on view */ #define OPEN_VIEW 8192 /* Allow open on view */
#define OPEN_VIEW_NO_PARSE 16384 /* Open frm only if it's a view,
but do not parse view itself */
#define SC_INFO_LENGTH 4 /* Form format constant */ #define SC_INFO_LENGTH 4 /* Form format constant */
#define TE_INFO_LENGTH 3 #define TE_INFO_LENGTH 3
#define MTYP_NOEMPTY_BIT 128 #define MTYP_NOEMPTY_BIT 128
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment