Skip to content

Commit 564824a

Browse files
committed
Display row information in processlist for rbr threads
Summary: Set row_query using the fields unpacked from the row event. Use row_query in show processlist. Test Plan: mtr Reviewers: tianx Reviewed By: tianx Subscribers: webscalesql-eng, ebergen Differential Revision: https://reviews.facebook.net/D61833
1 parent 2306b6e commit 564824a

6 files changed

+102
-9
lines changed

sql/log_event.cc

+3
Original file line numberDiff line numberDiff line change
@@ -12016,6 +12016,9 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
1201612016
if (thd->slave_thread)
1201712017
free_root(thd->mem_root, MYF(MY_KEEP_PREALLOC));
1201812018
}
12019+
mysql_mutex_lock(&thd->LOCK_thd_data);
12020+
thd->row_query.clear();
12021+
mysql_mutex_unlock(&thd->LOCK_thd_data);
1201912022
DBUG_RETURN(error);
1202012023

1202112024
err:

sql/log_event.h

+33-2
Original file line numberDiff line numberDiff line change
@@ -4346,11 +4346,42 @@ class Rows_log_event : public Log_event
43464346
int unpack_current_row(const Relay_log_info *const rli,
43474347
MY_BITMAP const *cols)
43484348
{
4349+
mysql_mutex_lock(&thd->LOCK_thd_data);
43494350
DBUG_ASSERT(m_table);
4351+
// For a update event we should not clear the query when unpacking after
4352+
// image. This can be checked using the cols parameter.
4353+
if (cols != &m_cols_ai)
4354+
thd->row_query.clear();
4355+
4356+
Log_event_type type = get_type_code();
4357+
if (type == WRITE_ROWS_EVENT || type == WRITE_ROWS_EVENT_V1)
4358+
thd->row_query = "INSERT INTO ";
4359+
else if (type == DELETE_ROWS_EVENT || type == DELETE_ROWS_EVENT_V1)
4360+
thd->row_query = "DELETE FROM ";
4361+
else
4362+
{
4363+
DBUG_ASSERT(type == UPDATE_ROWS_EVENT || type == UPDATE_ROWS_EVENT_V1);
4364+
if (cols != &m_cols_ai)
4365+
{
4366+
thd->row_query = "UPDATE ";
4367+
}
4368+
}
4369+
4370+
if (cols != &m_cols_ai)
4371+
{
4372+
thd->row_query.append(m_table->s->db.str, m_table->s->db.length);
4373+
thd->row_query.append(".");
4374+
thd->row_query.append(m_table->s->table_name.str,
4375+
m_table->s->table_name.length);
4376+
thd->row_query.append(" ");
4377+
}
43504378

43514379
ASSERT_OR_RETURN_ERROR(m_curr_row <= m_rows_end, HA_ERR_CORRUPT_EVENT);
4352-
return ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
4353-
&m_curr_row_end, &m_master_reclength, m_rows_end);
4380+
int res = ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
4381+
&m_curr_row_end, &m_master_reclength, m_rows_end,
4382+
&thd->row_query);
4383+
mysql_mutex_unlock(&thd->LOCK_thd_data);
4384+
return res;
43544385
}
43554386

43564387
/*

sql/rpl_record.cc

+49-3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,41 @@ pack_row(TABLE *table, MY_BITMAP const* cols,
156156
#endif
157157

158158
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
159+
static void insert_row_fields(std::string* row_query, TABLE* table)
160+
{
161+
static uint32_t max_field_len= 100;
162+
row_query->append("(");
163+
String buf;
164+
#ifndef DBUG_OFF
165+
uint index= 0;
166+
#endif
167+
for (Field **ptr=table->field; *ptr; ptr++)
168+
{
169+
#ifndef DBUG_OFF
170+
// Set the read bit to avoid assertions in val_str().
171+
bool flip= false;
172+
if (table->read_set && !bitmap_is_set(table->read_set, index))
173+
{
174+
flip= true;
175+
bitmap_flip_bit(table->read_set, index);
176+
}
177+
#endif
178+
String *s = (*ptr)->val_str(&buf, &buf);
179+
if (!s)
180+
row_query->append("NULL");
181+
else
182+
row_query->append(s->ptr(), min(max_field_len, s->length()));
183+
row_query->append(",");
184+
#ifndef DBUG_OFF
185+
if (flip)
186+
bitmap_flip_bit(table->read_set, index);
187+
++index;
188+
#endif
189+
}
190+
if (row_query->back() == ',')
191+
row_query->back() = ')';
192+
}
193+
159194
/**
160195
Unpack a row into @c table->record[0].
161196
@@ -181,6 +216,8 @@ pack_row(TABLE *table, MY_BITMAP const* cols,
181216
@param row_end
182217
Pointer to variable that will hold the value of the
183218
end position for the data in the row event
219+
@param row_query
220+
Append the fields to this string
184221
185222
@retval 0 No error
186223
@@ -195,7 +232,8 @@ int unpack_row_with_column_info(TABLE *table, uint const colcnt,
195232
ulong *const master_reclength,
196233
uchar const *const row_end,
197234
table_def* tabledef,
198-
TABLE *conv_table)
235+
TABLE *conv_table,
236+
std::string* row_query)
199237
{
200238
DBUG_ENTER("unpack_row_with_column_info");
201239
uchar const *null_bits= row_data;
@@ -273,6 +311,9 @@ int unpack_row_with_column_info(TABLE *table, uint const colcnt,
273311
}
274312
++null_bit_index;
275313
}
314+
315+
insert_row_fields(row_query, table);
316+
276317
*current_row_end = pack_ptr;
277318
if (master_reclength)
278319
{
@@ -318,6 +359,9 @@ int unpack_row_with_column_info(TABLE *table, uint const colcnt,
318359
Pointer to variable that will hold the value of the
319360
end position for the data in the row event
320361
362+
@param row_query
363+
Append the fields to this string
364+
321365
@retval 0 No error
322366
323367
@retval HA_ERR_GENERIC
@@ -328,7 +372,7 @@ unpack_row(Relay_log_info const *rli,
328372
TABLE *table, uint const colcnt,
329373
uchar const *const row_data, MY_BITMAP const *cols,
330374
uchar const **const current_row_end, ulong *const master_reclength,
331-
uchar const *const row_end)
375+
uchar const *const row_end, std::string* row_query)
332376
{
333377
DBUG_ENTER("unpack_row");
334378
DBUG_ASSERT(row_data);
@@ -382,7 +426,8 @@ unpack_row(Relay_log_info const *rli,
382426
{
383427
DBUG_RETURN(unpack_row_with_column_info(table, colcnt, row_data, cols,
384428
current_row_end, master_reclength,
385-
row_end, tabledef, conv_table));
429+
row_end, tabledef, conv_table,
430+
row_query));
386431
}
387432

388433
for (field_ptr= begin_ptr ; field_ptr < end_ptr && *field_ptr ; ++field_ptr)
@@ -568,6 +613,7 @@ unpack_row(Relay_log_info const *rli,
568613
}
569614
}
570615

616+
insert_row_fields(row_query, table);
571617
/*
572618
We should now have read all the null bytes, otherwise something is
573619
really wrong.

sql/rpl_record.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int unpack_row(Relay_log_info const *rli,
3434
TABLE *table, uint const colcnt,
3535
uchar const *const row_data, MY_BITMAP const *cols,
3636
uchar const **const curr_row_end, ulong *const master_reclength,
37-
uchar const *const row_end);
37+
uchar const *const row_end, std::string* row_query= nullptr);
3838

3939
// Fill table's record[0] with default values.
4040
int prepare_record(TABLE *const table, const MY_BITMAP *cols, const bool check);

sql/sql_class.h

+2
Original file line numberDiff line numberDiff line change
@@ -4612,6 +4612,8 @@ class THD :public MDL_context_owner,
46124612

46134613
// propagate value from rli
46144614
bool skip_unique_check();
4615+
// protected by LOCK_thd_data
4616+
std::string row_query;
46154617
};
46164618

46174619
/**

sql/sql_show.cc

+14-3
Original file line numberDiff line numberDiff line change
@@ -2197,10 +2197,21 @@ static void set_thread_info_common(thread_info *thd_info, THD *thd, THD *tmp,
21972197
thd_info->rows_examined= tmp->get_examined_row_count();
21982198
thd_info->rows_sent= tmp->get_sent_row_count();
21992199
/* Lock THD mutex that protects its data when looking at it. */
2200-
if (tmp->query())
2200+
const char* query = NULL;
2201+
uint length = 0;
2202+
if (!tmp->row_query.empty())
2203+
{
2204+
query = tmp->row_query.c_str();
2205+
length = tmp->row_query.length();
2206+
}
2207+
else if (tmp->query())
22012208
{
2202-
uint length= min<uint>(max_query_length, tmp->query_length());
2203-
char *q= thd->strmake(tmp->query(),length);
2209+
query = tmp->query();
2210+
length = tmp->query_length();
2211+
}
2212+
if (query) {
2213+
length= min<uint>(max_query_length, length);
2214+
char *q= thd->strmake(query,length);
22042215
/* Safety: in case strmake failed, we set length to 0. */
22052216
thd_info->query_string=
22062217
CSET_STRING(q, q ? length : 0, tmp->query_charset());

0 commit comments

Comments
 (0)