16
16
*/
17
17
18
18
#include " mysql_object_reader.h"
19
+ #include < boost/algorithm/string.hpp>
19
20
20
21
using namespace Mysql ::Tools::Dump;
21
22
@@ -24,6 +25,7 @@ void Mysql_object_reader::Rows_fetching_context::acquire_fields_information(
24
25
{
25
26
MYSQL_FIELD* fields= mysql_fetch_fields (mysql_result);
26
27
uint field_count= mysql_num_fields (mysql_result);
28
+ m_fields.reserve (field_count);
27
29
for (uint i= 0 ; i < field_count; ++i)
28
30
m_fields.push_back (Mysql_field (&fields[i]));
29
31
}
@@ -56,11 +58,13 @@ int64 Mysql_object_reader::Rows_fetching_context::result_callback(
56
58
}
57
59
58
60
Mysql_object_reader::Rows_fetching_context::Rows_fetching_context (
59
- Mysql_object_reader* parent, Item_processing_data* item_processing)
61
+ Mysql_object_reader* parent, Item_processing_data* item_processing,
62
+ bool has_generated_column)
60
63
: m_parent(parent),
61
64
m_item_processing(item_processing),
62
65
m_row_group((Table*)item_processing
63
- ->get_process_task_object()->get_related_db_object(), m_fields)
66
+ ->get_process_task_object()->get_related_db_object(), m_fields,
67
+ has_generated_column)
64
68
{
65
69
m_row_group.m_rows .reserve (
66
70
(size_t )m_parent->m_options ->m_row_group_size );
@@ -75,18 +79,44 @@ void Mysql_object_reader::read_table_rows_task(
75
79
Table_rows_dump_task* table_rows_dump_task,
76
80
Item_processing_data* item_to_process)
77
81
{
82
+ bool has_generated_columns= 0 ;
78
83
Mysql::Tools::Base::Mysql_query_runner* runner= this ->get_runner ();
79
84
Table* table= table_rows_dump_task->get_related_table ();
80
85
86
+ std::vector<const Mysql::Tools::Base::Mysql_query_runner::Row*> columns;
87
+ std::vector<std::string> field_names;
88
+
89
+ runner->run_query_store (
90
+ " SELECT `COLUMN_NAME`, `EXTRA` FROM " +
91
+ this ->get_quoted_object_full_name (" INFORMATION_SCHEMA" , " COLUMNS" ) +
92
+ " WHERE TABLE_SCHEMA ='" + runner->escape_string (table->get_schema ()) +
93
+ " ' AND TABLE_NAME ='" + runner->escape_string (table->get_name ()) + " '" ,
94
+ &columns);
95
+
96
+ std::string column_names;
97
+ for (std::vector<const Mysql::Tools::Base::Mysql_query_runner::Row*>::iterator
98
+ it= columns.begin (); it != columns.end (); ++it)
99
+ {
100
+ const Mysql::Tools::Base::Mysql_query_runner::Row& column_data= **it;
101
+ if (column_data[1 ] == " STORED GENERATED" ||
102
+ column_data[1 ] == " VIRTUAL GENERATED" )
103
+ has_generated_columns= 1 ;
104
+ else
105
+ column_names+= this ->quote_name (column_data[0 ]) + " ," ;
106
+ }
107
+ /* remove last comma from column_names */
108
+ column_names= boost::algorithm::replace_last_copy (column_names, " ," , " " );
109
+
81
110
Rows_fetching_context* row_fetching_context=
82
- new Rows_fetching_context (this , item_to_process);
111
+ new Rows_fetching_context (this , item_to_process, has_generated_columns );
83
112
84
113
runner->run_query (
85
- " SELECT SQL_NO_CACHE * FROM " + this ->get_quoted_object_full_name (table),
114
+ " SELECT SQL_NO_CACHE " + column_names + " FROM " +
115
+ this ->get_quoted_object_full_name (table),
86
116
new Mysql::Instance_callback<
87
117
int64, const Mysql::Tools::Base::Mysql_query_runner::Row&,
88
- Rows_fetching_context>(
89
- row_fetching_context, &Rows_fetching_context::result_callback));
118
+ Rows_fetching_context>(
119
+ row_fetching_context, &Rows_fetching_context::result_callback));
90
120
91
121
row_fetching_context->process_buffer ();
92
122
if (row_fetching_context->is_all_rows_processed ())
0 commit comments