mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
SQL: helpers to get archive tables list [closes #199]
This commit is contained in:
@ -4218,7 +4218,7 @@ int schema_tables_add(THD *thd, Dynamic_array<LEX_STRING*> *files,
|
|||||||
@retval 2 Not fatal error; Safe to ignore this file list
|
@retval 2 Not fatal error; Safe to ignore this file list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
int
|
||||||
make_table_name_list(THD *thd, Dynamic_array<LEX_STRING*> *table_names,
|
make_table_name_list(THD *thd, Dynamic_array<LEX_STRING*> *table_names,
|
||||||
LEX *lex, LOOKUP_FIELD_VALUES *lookup_field_vals,
|
LEX *lex, LOOKUP_FIELD_VALUES *lookup_field_vals,
|
||||||
LEX_STRING *db_name)
|
LEX_STRING *db_name)
|
||||||
|
@ -199,6 +199,9 @@ typedef struct st_lookup_field_values
|
|||||||
bool wild_table_value;
|
bool wild_table_value;
|
||||||
} LOOKUP_FIELD_VALUES;
|
} LOOKUP_FIELD_VALUES;
|
||||||
|
|
||||||
|
int make_table_name_list(THD *thd, Dynamic_array<LEX_STRING *> *table_names,
|
||||||
|
LEX *lex, LOOKUP_FIELD_VALUES *lookup_field_vals,
|
||||||
|
LEX_STRING *db_name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
INFORMATION_SCHEMA: Execution plan for get_all_tables() call
|
INFORMATION_SCHEMA: Execution plan for get_all_tables() call
|
||||||
|
71
sql/vtmd.cc
71
sql/vtmd.cc
@ -6,6 +6,7 @@
|
|||||||
#include "sql_select.h"
|
#include "sql_select.h"
|
||||||
#include "table_cache.h" // tdc_remove_table()
|
#include "table_cache.h" // tdc_remove_table()
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
#include "sql_show.h"
|
||||||
|
|
||||||
LString VERS_VTMD_TEMPLATE(C_STRING_WITH_LEN("vtmd_template"));
|
LString VERS_VTMD_TEMPLATE(C_STRING_WITH_LEN("vtmd_template"));
|
||||||
|
|
||||||
@ -573,3 +574,73 @@ err:
|
|||||||
close_log_table(thd, &open_tables_backup);
|
close_log_table(thd, &open_tables_backup);
|
||||||
return error ? true : false;
|
return error ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dynamic_array<String> VTMD_table::get_archive_tables(THD *thd)
|
||||||
|
{
|
||||||
|
Dynamic_array<String> result;
|
||||||
|
|
||||||
|
Dynamic_array<LEX_STRING *> vtmd_tables= get_vtmd_tables(thd);
|
||||||
|
for (uint i= 0; i < vtmd_tables.elements(); i++)
|
||||||
|
{
|
||||||
|
LEX_STRING table_name= *vtmd_tables.at(i);
|
||||||
|
|
||||||
|
Open_tables_backup open_tables_backup;
|
||||||
|
TABLE_LIST table_list;
|
||||||
|
// Assume VTMD tables belongs to current db.
|
||||||
|
table_list.init_one_table(thd->db, strlen(thd->db),
|
||||||
|
LEX_STRING_WITH_LEN(table_name), table_name.str,
|
||||||
|
TL_READ);
|
||||||
|
|
||||||
|
TABLE *table= open_log_table(thd, &table_list, &open_tables_backup);
|
||||||
|
if (!table)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
READ_RECORD read_record;
|
||||||
|
int error= 0;
|
||||||
|
SQL_SELECT *sql_select= make_select(table, 0, 0, NULL, NULL, 0, &error);
|
||||||
|
if (error)
|
||||||
|
goto error1;
|
||||||
|
if (error = init_read_record(&read_record, thd, table, sql_select, NULL, 1, 1,
|
||||||
|
false))
|
||||||
|
goto error2;
|
||||||
|
|
||||||
|
while (!(error= read_record.read_record(&read_record)))
|
||||||
|
{
|
||||||
|
Field *field= table->field[FLD_ARCHIVE_NAME];
|
||||||
|
if (field->is_null())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String archive_name;
|
||||||
|
field->val_str(&archive_name);
|
||||||
|
archive_name.set_ascii(strmake_root(thd->mem_root, archive_name.c_ptr(),
|
||||||
|
archive_name.length()),
|
||||||
|
archive_name.length());
|
||||||
|
result.push(archive_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
end_read_record(&read_record);
|
||||||
|
error2:
|
||||||
|
delete sql_select;
|
||||||
|
error1:
|
||||||
|
close_log_table(thd, &open_tables_backup);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dynamic_array<LEX_STRING *> get_vtmd_tables(THD *thd)
|
||||||
|
{
|
||||||
|
// Note function retrieves table names from current db only.
|
||||||
|
LOOKUP_FIELD_VALUES lookup_field_values= {
|
||||||
|
*thd->make_lex_string(thd->db, strlen(thd->db)),
|
||||||
|
*thd->make_lex_string(C_STRING_WITH_LEN("%_vtmd")), false, true};
|
||||||
|
|
||||||
|
Dynamic_array<LEX_STRING *> table_names;
|
||||||
|
make_table_name_list(thd, &table_names, thd->lex, &lookup_field_values,
|
||||||
|
&lookup_field_values.db_value);
|
||||||
|
|
||||||
|
return table_names;
|
||||||
|
}
|
||||||
|
@ -87,8 +87,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool find_archive_name(THD *thd, String &out);
|
bool find_archive_name(THD *thd, String &out);
|
||||||
|
|
||||||
|
static Dynamic_array<String> get_archive_tables(THD *thd);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Dynamic_array<LEX_STRING *> get_vtmd_tables(THD *thd);
|
||||||
|
|
||||||
class VTMD_exists : public VTMD_table
|
class VTMD_exists : public VTMD_table
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
Reference in New Issue
Block a user