Skip to content

Commit 7a65dcb

Browse files
committed
MDEV-34704 Quick mode produces the bug for mariadb client
--quick-max-column-width parameter added to limit field width in --quick mode.
1 parent cb5bb4b commit 7a65dcb

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

client/mysql.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static my_bool column_types_flag;
255255
static my_bool preserve_comments= 0;
256256
static my_bool in_com_source, aborted= 0;
257257
static ulong opt_max_allowed_packet, opt_net_buffer_length;
258+
unsigned long quick_max_column_width= LONG_MAX;
258259
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
259260
static uint my_end_arg;
260261
static char * opt_mysql_unix_port=0;
@@ -1821,6 +1822,10 @@ static struct my_option my_long_options[] =
18211822
"Don't cache result, print it row by row. This may slow down the server "
18221823
"if the output is suspended. Doesn't use history file.",
18231824
&quick, &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1825+
{"quick-max-column-width", 0,
1826+
"Maximal field length limit in case of --qick", &quick_max_column_width,
1827+
&quick_max_column_width, 0, GET_ULONG, REQUIRED_ARG, LONG_MAX, 0, ULONG_MAX,
1828+
0, 1, 0},
18241829
{"raw", 'r', "Write fields without conversion. Used with --batch.",
18251830
&opt_raw_data, &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
18261831
{"reconnect", 0, "Reconnect if the connection is lost.",
@@ -3877,7 +3882,7 @@ print_table_data(MYSQL_RES *result)
38773882
{
38783883
uint length= column_names ? field->name_length : 0;
38793884
if (quick)
3880-
length= MY_MAX(length,field->length);
3885+
length= MY_MAX(length, MY_MIN(field->length, quick_max_column_width));
38813886
else
38823887
length= MY_MAX(length,field->max_length);
38833888
if (length < 4 && !IS_NOT_NULL(field->flags))

mysql-test/main/client.result

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# MDEV-34704: Quick mode produces the bug for mariadb client
3+
#
4+
create table t1 (aaaaaaaaa char (5), aaaaa char (10), a char (127), b char(1));
5+
insert into t1 values ("X", "X", "X", "X");
6+
# --table --quick
7+
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------+------+
8+
| aaaaaaaaa | aaaaa | a | b |
9+
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------+------+
10+
| X | X | X | X |
11+
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------+------+
12+
# --table --quick --quick-max-column-width=0
13+
+-----------+-------+------+------+
14+
| aaaaaaaaa | aaaaa | a | b |
15+
+-----------+-------+------+------+
16+
| X | X | X | X |
17+
+-----------+-------+------+------+
18+
# --table --quick --quick-max-column-width=10
19+
+-----------+------------+------------+------+
20+
| aaaaaaaaa | aaaaa | a | b |
21+
+-----------+------------+------------+------+
22+
| X | X | X | X |
23+
+-----------+------------+------------+------+
24+
# --table --quick --quick-max-column-width=20
25+
+-----------+------------+----------------------+------+
26+
| aaaaaaaaa | aaaaa | a | b |
27+
+-----------+------------+----------------------+------+
28+
| X | X | X | X |
29+
+-----------+------------+----------------------+------+
30+
insert into t1 values ("01234", "0123456789", "01234567890123456789", "1");
31+
# --table --quick
32+
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------+------+
33+
| aaaaaaaaa | aaaaa | a | b |
34+
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------+------+
35+
| X | X | X | X |
36+
| 01234 | 0123456789 | 01234567890123456789 | 1 |
37+
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------+------+
38+
# --table --quick --quick-max-column-width=0
39+
+-----------+-------+------+------+
40+
| aaaaaaaaa | aaaaa | a | b |
41+
+-----------+-------+------+------+
42+
| X | X | X | X |
43+
| 01234 | 0123456789 | 01234567890123456789 | 1 |
44+
+-----------+-------+------+------+
45+
# --table --quick --quick-max-column-width=10
46+
+-----------+------------+------------+------+
47+
| aaaaaaaaa | aaaaa | a | b |
48+
+-----------+------------+------------+------+
49+
| X | X | X | X |
50+
| 01234 | 0123456789 | 01234567890123456789 | 1 |
51+
+-----------+------------+------------+------+
52+
# --table --quick --quick-max-column-width=20
53+
+-----------+------------+----------------------+------+
54+
| aaaaaaaaa | aaaaa | a | b |
55+
+-----------+------------+----------------------+------+
56+
| X | X | X | X |
57+
| 01234 | 0123456789 | 01234567890123456789 | 1 |
58+
+-----------+------------+----------------------+------+
59+
drop table t1;
60+
#
61+
# End of 10.7 tests
62+
#

mysql-test/main/client.test

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--source include/not_embedded.inc
2+
3+
--echo #
4+
--echo # MDEV-34704: Quick mode produces the bug for mariadb client
5+
--echo #
6+
7+
8+
create table t1 (aaaaaaaaa char (5), aaaaa char (10), a char (127), b char(1));
9+
insert into t1 values ("X", "X", "X", "X");
10+
11+
12+
--echo # --table --quick
13+
--exec echo "select * from test.t1;" | $MYSQL --table --quick 2>&1
14+
15+
16+
--echo # --table --quick --quick-max-column-width=0
17+
--exec echo "select * from test.t1;" | $MYSQL --table --quick --quick-max-column-width=0 2>&1
18+
19+
20+
--echo # --table --quick --quick-max-column-width=10
21+
--exec echo "select * from test.t1;" | $MYSQL --table --quick --quick-max-column-width=10 2>&1
22+
23+
24+
--echo # --table --quick --quick-max-column-width=20
25+
--exec echo "select * from test.t1;" | $MYSQL --table --quick --quick-max-column-width=20 2>&1
26+
27+
insert into t1 values ("01234", "0123456789", "01234567890123456789", "1");
28+
29+
--echo # --table --quick
30+
--exec echo "select * from test.t1;" | $MYSQL --table --quick 2>&1
31+
32+
33+
--echo # --table --quick --quick-max-column-width=0
34+
--exec echo "select * from test.t1;" | $MYSQL --table --quick --quick-max-column-width=0 2>&1
35+
36+
--echo # --table --quick --quick-max-column-width=10
37+
--exec echo "select * from test.t1;" | $MYSQL --table --quick --quick-max-column-width=10 2>&1
38+
39+
--echo # --table --quick --quick-max-column-width=20
40+
--exec echo "select * from test.t1;" | $MYSQL --table --quick --quick-max-column-width=20 2>&1
41+
42+
drop table t1;
43+
44+
--echo #
45+
--echo # End of 10.7 tests
46+
--echo #

0 commit comments

Comments
 (0)