summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kosov <claprix@yandex.ru>2017-09-25 11:29:16 +0300
committerEugene Kosov <claprix@yandex.ru>2017-09-25 22:06:53 +0300
commitf79c4469ff8a17dee54f41786b76197dc2e17626 (patch)
tree906d097e119ec2acbd6df4b92f62464ad9be21e1
parent7f2064780cb8960697bef17c7ae63be565690eec (diff)
downloadmariadb-git-f79c4469ff8a17dee54f41786b76197dc2e17626.tar.gz
SQL: helpers to get archive tables list [closes #199]
-rw-r--r--sql/sql_show.cc2
-rw-r--r--sql/sql_show.h3
-rw-r--r--sql/vtmd.cc71
-rw-r--r--sql/vtmd.h4
4 files changed, 79 insertions, 1 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 30fd1b43e4c..ac340892505 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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
*/
-static int
+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)
diff --git a/sql/sql_show.h b/sql/sql_show.h
index e93b855450c..03ff539e959 100644
--- a/sql/sql_show.h
+++ b/sql/sql_show.h
@@ -199,6 +199,9 @@ typedef struct st_lookup_field_values
bool wild_table_value;
} 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
diff --git a/sql/vtmd.cc b/sql/vtmd.cc
index 58d9bb311bb..aa9245570f4 100644
--- a/sql/vtmd.cc
+++ b/sql/vtmd.cc
@@ -6,6 +6,7 @@
#include "sql_select.h"
#include "table_cache.h" // tdc_remove_table()
#include "key.h"
+#include "sql_show.h"
LString VERS_VTMD_TEMPLATE(C_STRING_WITH_LEN("vtmd_template"));
@@ -573,3 +574,73 @@ err:
close_log_table(thd, &open_tables_backup);
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;
+}
diff --git a/sql/vtmd.h b/sql/vtmd.h
index 8588462f83f..8a838dc2f88 100644
--- a/sql/vtmd.h
+++ b/sql/vtmd.h
@@ -87,8 +87,12 @@ public:
}
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
{
protected: