mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-01 18:25:59 +00:00
Quote chunk col in char chunk sql.
This commit is contained in:
@@ -530,10 +530,11 @@ sub _chunk_char {
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless defined $args{$arg};
|
||||
}
|
||||
my $q = $self->{Quoter};
|
||||
my $db_tbl = $q->quote($args{db}, $args{tbl});
|
||||
my $dbh = $args{dbh};
|
||||
my $chunk_col = $args{chunk_col};
|
||||
my $q = $self->{Quoter};
|
||||
my $db_tbl = $q->quote($args{db}, $args{tbl});
|
||||
my $dbh = $args{dbh};
|
||||
my $chunk_col = $args{chunk_col};
|
||||
my $qchunk_col = $q->quote($args{chunk_col});
|
||||
my $row;
|
||||
my $sql;
|
||||
|
||||
@@ -610,9 +611,9 @@ sub _chunk_char {
|
||||
# returned like [a, B, c, d, é, ..., ü] then we have a base 42
|
||||
# system where 0=a, 1=B, 2=c, 3=d, 4=é, ... 41=ü. count_base()
|
||||
# helps us count in arbitrary systems.
|
||||
$sql = "SELECT `$chunk_col` FROM $tmp_db_tbl "
|
||||
. "WHERE `$chunk_col` BETWEEN ? AND ? "
|
||||
. "ORDER BY `$chunk_col`";
|
||||
$sql = "SELECT $qchunk_col FROM $tmp_db_tbl "
|
||||
. "WHERE $qchunk_col BETWEEN ? AND ? "
|
||||
. "ORDER BY $qchunk_col";
|
||||
PTDEBUG && _d($dbh, $sql);
|
||||
my $sel_char_sth = $dbh->prepare($sql);
|
||||
$sel_char_sth->execute($min_col, $max_col);
|
||||
@@ -639,9 +640,9 @@ sub _chunk_char {
|
||||
# [ant, apple, azur, boy]. We assume data is more evenly distributed
|
||||
# than not so we use the minimum number of characters to express a chunk
|
||||
# size.
|
||||
$sql = "SELECT MAX(LENGTH($chunk_col)) FROM $db_tbl "
|
||||
$sql = "SELECT MAX(LENGTH($qchunk_col)) FROM $db_tbl "
|
||||
. ($args{where} ? "WHERE $args{where} " : "")
|
||||
. "ORDER BY `$chunk_col`";
|
||||
. "ORDER BY $qchunk_col";
|
||||
PTDEBUG && _d($dbh, $sql);
|
||||
$row = $dbh->selectrow_arrayref($sql);
|
||||
my $max_col_len = $row->[0];
|
||||
@@ -682,7 +683,7 @@ sub _chunk_char {
|
||||
};
|
||||
|
||||
return (
|
||||
col => $q->quote($chunk_col),
|
||||
col => $qchunk_col,
|
||||
start_point => 0,
|
||||
end_point => $n_values,
|
||||
interval => $interval,
|
||||
|
@@ -26,7 +26,7 @@ if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 91;
|
||||
plan tests => 93;
|
||||
}
|
||||
|
||||
$sb->create_dbs($dbh, ['test']);
|
||||
@@ -1202,7 +1202,7 @@ is(
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Issue Bug #897758: TableChunker dies from an uninit value
|
||||
# Bug #897758: TableChunker dies from an uninit value
|
||||
# #############################################################################
|
||||
|
||||
@chunks = $c->calculate_chunks(
|
||||
@@ -1310,6 +1310,49 @@ is(
|
||||
# %params,
|
||||
#);
|
||||
|
||||
# #############################################################################
|
||||
# Bug 967451: Char chunking doesn't quote column name
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "t/lib/samples/char-chunking/ascii.sql", 'test');
|
||||
$dbh->do("ALTER TABLE test.ascii CHANGE COLUMN c `key` char(64) NOT NULL");
|
||||
$t = $tp->parse( $tp->get_create_table($dbh, 'test', 'ascii') );
|
||||
|
||||
%params = $c->get_range_statistics(
|
||||
dbh => $dbh,
|
||||
db => 'test',
|
||||
tbl => 'ascii',
|
||||
chunk_col => 'key',
|
||||
tbl_struct => $t,
|
||||
);
|
||||
is_deeply(
|
||||
\%params,
|
||||
{
|
||||
min => '',
|
||||
max => 'ZESUS!!!',
|
||||
rows_in_range => '142',
|
||||
},
|
||||
"Range stats for `key` col (bug 967451)"
|
||||
);
|
||||
|
||||
@chunks = $c->calculate_chunks(
|
||||
dbh => $dbh,
|
||||
db => 'test',
|
||||
tbl => 'ascii',
|
||||
tbl_struct => $t,
|
||||
chunk_col => 'key',
|
||||
chunk_size => '50',
|
||||
%params,
|
||||
);
|
||||
is_deeply(
|
||||
\@chunks,
|
||||
[
|
||||
"`key` < '5'",
|
||||
"`key` >= '5' AND `key` < 'I'",
|
||||
"`key` >= 'I'",
|
||||
],
|
||||
"Caclulate chunks for `key` col (bug 967451)"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
Reference in New Issue
Block a user