mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-05 01:05:45 +08:00
Fix sakila.film_actor error.
This commit is contained in:
@@ -3514,46 +3514,47 @@ sub new {
|
||||
index => $index,
|
||||
asc_only => 1,
|
||||
);
|
||||
MKDEBUG && _d('Ascend params:', Dumper($asc));
|
||||
|
||||
my $from = $q->quote(@{$tbl}{qw(db tbl)}) . " FORCE INDEX(`$index`)";
|
||||
my $order_by = join(', ', map {$q->quote($_)} @{$index_cols});
|
||||
|
||||
my $first_lb_sql
|
||||
= "SELECT /*!40001 SQL_NO_CACHE */ "
|
||||
. join(', ', map { $q->quote($_) } @{$index_cols})
|
||||
. " FROM $from "
|
||||
. join(', ', map { $q->quote($_) } @{$asc->{scols}})
|
||||
. " FROM $from"
|
||||
. ($args{where} ? " WHERE $args{where}" : '')
|
||||
. " ORDER BY $order_by "
|
||||
. " ORDER BY $order_by"
|
||||
. " LIMIT 1"
|
||||
. " /*first lower boundary*/";
|
||||
MKDEBUG && _d('First lower boundary statement:', $first_lb_sql);
|
||||
|
||||
my $last_ub_sql
|
||||
= "SELECT /*!40001 SQL_NO_CACHE */ "
|
||||
. join(', ', map { $q->quote($_) } @{$index_cols})
|
||||
. " FROM $from "
|
||||
. join(', ', map { $q->quote($_) } @{$asc->{scols}})
|
||||
. " FROM $from"
|
||||
. ($args{where} ? " WHERE $args{where}" : '')
|
||||
. " ORDER BY $order_by DESC "
|
||||
. " ORDER BY "
|
||||
. join(' DESC, ', map {$q->quote($_)} @{$index_cols}) . ' DESC'
|
||||
. " LIMIT 1"
|
||||
. " /*last upper boundary*/";
|
||||
MKDEBUG && _d('Last upper boundary statement:', $last_ub_sql);
|
||||
|
||||
my $ub_sql
|
||||
= "SELECT /*!40001 SQL_NO_CACHE */ "
|
||||
. join(', ', map { $q->quote($_) } @{$index_cols})
|
||||
. " FROM $from "
|
||||
. " WHERE " . $asc->{boundaries}->{'>='} # lower boundary
|
||||
. ($args{where} ? " AND ($args{where})" : '')
|
||||
. " ORDER BY $order_by "
|
||||
. " LIMIT 2 OFFSET " . (($o->get('chunk-size') || 1) - 1)
|
||||
. " /*upper boundary*/";
|
||||
MKDEBUG && _d('Next upper boundary statement:', $ub_sql);
|
||||
my $ub_sql = _make_ub_sql(
|
||||
cols => $asc->{scols},
|
||||
from => $from,
|
||||
where => $asc->{boundaries}->{'>='}
|
||||
. ($args{where} ? " AND ($args{where})" : ''),
|
||||
order_by => $order_by,
|
||||
limit => $o->get('chunk-size'),
|
||||
Quoter => $q,
|
||||
);
|
||||
|
||||
my $nibble_sql
|
||||
= ($args{dms} ? "$args{dms} " : "SELECT ")
|
||||
. ($args{select} ? $args{select}
|
||||
: join(', ', map { $q->quote($_) } @{$asc->{cols}}))
|
||||
. " FROM $from "
|
||||
. " FROM $from"
|
||||
. " WHERE " . $asc->{boundaries}->{'>='} # lower boundary
|
||||
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
||||
. ($args{where} ? " AND ($args{where})" : '')
|
||||
@@ -3565,7 +3566,7 @@ sub new {
|
||||
= "EXPLAIN SELECT "
|
||||
. ($args{select} ? $args{select}
|
||||
: join(', ', map { $q->quote($_) } @{$asc->{cols}}))
|
||||
. " FROM $from "
|
||||
. " FROM $from"
|
||||
. " WHERE " . $asc->{boundaries}->{'>='} # lower boundary
|
||||
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
||||
. ($args{where} ? " AND ($args{where})" : '')
|
||||
@@ -3577,7 +3578,7 @@ sub new {
|
||||
= ($args{dms} ? "$args{dms} " : "SELECT ")
|
||||
. ($args{select} ? $args{select}
|
||||
: join(', ', map { $q->quote($_) } @{$asc->{cols}}))
|
||||
. " FROM $from "
|
||||
. " FROM $from"
|
||||
. ($args{where} ? " AND ($args{where})" : '')
|
||||
. " ORDER BY $order_by"
|
||||
. " /*one nibble*/";
|
||||
@@ -3587,7 +3588,7 @@ sub new {
|
||||
= "EXPLAIN SELECT "
|
||||
. ($args{select} ? $args{select}
|
||||
: join(', ', map { $q->quote($_) } @{$asc->{cols}}))
|
||||
. " FROM $from "
|
||||
. " FROM $from"
|
||||
. ($args{where} ? " AND ($args{where})" : '')
|
||||
. " ORDER BY $order_by"
|
||||
. " /*explain one nibble*/";
|
||||
@@ -3595,7 +3596,10 @@ sub new {
|
||||
|
||||
my $self = {
|
||||
%args,
|
||||
asc => $asc,
|
||||
index => $index,
|
||||
from => $from,
|
||||
order_by => $order_by,
|
||||
first_lb_sql => $first_lb_sql,
|
||||
last_ub_sql => $last_ub_sql,
|
||||
ub_sql => $ub_sql,
|
||||
@@ -3623,7 +3627,7 @@ sub next {
|
||||
}
|
||||
}
|
||||
|
||||
BOUNDARY:
|
||||
NIBBLE:
|
||||
while ( $self->{have_rows} || $self->_next_boundaries() ) {
|
||||
if ( !$self->{have_rows} ) {
|
||||
$self->{nibbleno}++;
|
||||
@@ -3684,6 +3688,49 @@ sub nibble_number {
|
||||
return $self->{nibbleno};
|
||||
}
|
||||
|
||||
sub set_chunk_size {
|
||||
my ($self, $limit) = @_;
|
||||
MKDEBUG && _d('Setting new chunk size (LIMIT):', $limit);
|
||||
|
||||
$self->{ub_sql} = _make_ub_sql(
|
||||
cols => $self->{asc}->{scols},
|
||||
from => $self->{from},
|
||||
where => $self->{asc}->{boundaries}->{'>='}
|
||||
. ($self->{where} ? " AND ($self->{where})" : ''),
|
||||
order_by => $self->{order_by},
|
||||
limit => $limit,
|
||||
Quoter => $self->{Quoter},
|
||||
);
|
||||
|
||||
if ($self->{ub_sth}) {
|
||||
$self->{ub_sth}->finish();
|
||||
$self->{ub_sth} = undef;
|
||||
}
|
||||
|
||||
$self->_prepare_sths();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub _make_ub_sql {
|
||||
my (%args) = @_;
|
||||
my @required_args = qw(cols from where order_by limit Quoter);
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my ($cols, $from, $where, $order_by, $limit, $q) = @args{@required_args};
|
||||
my $ub_sql
|
||||
= "SELECT /*!40001 SQL_NO_CACHE */ "
|
||||
. join(', ', map { $q->quote($_) } @{$cols})
|
||||
. " FROM $from"
|
||||
. " WHERE $where"
|
||||
. " ORDER BY $order_by"
|
||||
. " LIMIT 2 OFFSET " . ((int($limit) || 1) - 1)
|
||||
. " /*upper boundary*/";
|
||||
MKDEBUG && _d('Upper boundary statement:', $ub_sql);
|
||||
return $ub_sql;
|
||||
}
|
||||
|
||||
sub _can_nibble_once {
|
||||
my ($self) = @_;
|
||||
my ($dbh, $tbl, $q) = @{$self}{qw(dbh tbl Quoter)};
|
||||
@@ -3712,13 +3759,18 @@ sub _prepare_sths {
|
||||
my ($self) = @_;
|
||||
MKDEBUG && _d('Preparing statement handles');
|
||||
if ( $self->{one_nibble} ) {
|
||||
$self->{nibble_sth} = $self->{dbh}->prepare($self->{one_nibble_sql});
|
||||
$self->{explain_sth} = $self->{dbh}->prepare($self->{explain_one_nibble_sql});
|
||||
$self->{nibble_sth} = $self->{dbh}->prepare($self->{one_nibble_sql})
|
||||
unless $self->{nibble_sth};
|
||||
$self->{explain_sth} = $self->{dbh}->prepare($self->{explain_one_nibble_sql})
|
||||
unless $self->{explain_sth};
|
||||
}
|
||||
else {
|
||||
$self->{ub_sth} = $self->{dbh}->prepare($self->{ub_sql});
|
||||
$self->{nibble_sth} = $self->{dbh}->prepare($self->{nibble_sql});
|
||||
$self->{explain_sth} = $self->{dbh}->prepare($self->{explain_nibble_sql});
|
||||
$self->{ub_sth} = $self->{dbh}->prepare($self->{ub_sql})
|
||||
unless $self->{ub_sth};
|
||||
$self->{nibble_sth} = $self->{dbh}->prepare($self->{nibble_sql})
|
||||
unless $self->{nibble_sth};
|
||||
$self->{explain_sth} = $self->{dbh}->prepare($self->{explain_nibble_sql})
|
||||
unless $self->{explain_sth};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user