mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-22 20:19:00 +00:00
Update SchemaIterator, TableParser, and NibbleIterator in tools that use them. All tools' tests still pass.
This commit is contained in:
@@ -3941,22 +3941,15 @@ sub _get_index_cardinality {
|
||||
|
||||
sub get_row_estimate {
|
||||
my (%args) = @_;
|
||||
my @required_args = qw(Cxn tbl OptionParser TableParser Quoter);
|
||||
my ($cxn, $tbl, $o, $tp, $q) = @args{@required_args};
|
||||
my @required_args = qw(Cxn tbl);
|
||||
my ($cxn, $tbl) = @args{@required_args};
|
||||
|
||||
if ( $args{where} ) {
|
||||
PTDEBUG && _d('WHERE clause, using explain plan for row estimate');
|
||||
my $table = $q->quote(@{$tbl}{qw(db tbl)});
|
||||
my $sql = "EXPLAIN SELECT * FROM $table WHERE $args{where}";
|
||||
PTDEBUG && _d($sql);
|
||||
my $expl = $cxn->dbh()->selectrow_hashref($sql);
|
||||
PTDEBUG && _d(Dumper($expl));
|
||||
return ($expl->{rows} || 0), $expl->{key};
|
||||
}
|
||||
else {
|
||||
PTDEBUG && _d('No WHERE clause, using table status for row estimate');
|
||||
return $tbl->{tbl_status}->{rows} || 0;
|
||||
}
|
||||
my $sql = "EXPLAIN SELECT * FROM $tbl->{name} "
|
||||
. "WHERE " . ($args{where} || '1=1');
|
||||
PTDEBUG && _d($sql);
|
||||
my $expl = $cxn->dbh()->selectrow_hashref($sql);
|
||||
PTDEBUG && _d(Dumper($expl));
|
||||
return ($expl->{rows} || 0), $expl->{key};
|
||||
}
|
||||
|
||||
sub _prepare_sths {
|
||||
@@ -4543,7 +4536,7 @@ my $tbl_name = qr{
|
||||
|
||||
sub new {
|
||||
my ( $class, %args ) = @_;
|
||||
my @required_args = qw(OptionParser Quoter);
|
||||
my @required_args = qw(OptionParser TableParser Quoter);
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
@@ -4647,25 +4640,18 @@ sub next {
|
||||
}
|
||||
|
||||
if ( $schema_obj ) {
|
||||
if ( $schema_obj->{ddl} && $self->{TableParser} ) {
|
||||
$schema_obj->{tbl_struct}
|
||||
= $self->{TableParser}->parse($schema_obj->{ddl});
|
||||
}
|
||||
|
||||
delete $schema_obj->{ddl} unless $self->{keep_ddl};
|
||||
delete $schema_obj->{tbl_status} unless $self->{keep_tbl_status};
|
||||
|
||||
if ( my $schema = $self->{Schema} ) {
|
||||
$schema->add_schema_object($schema_obj);
|
||||
}
|
||||
PTDEBUG && _d('Next schema object:', $schema_obj->{db}, $schema_obj->{tbl});
|
||||
PTDEBUG && _d('Next schema object:',
|
||||
$schema_obj->{db}, $schema_obj->{tbl});
|
||||
}
|
||||
|
||||
return $schema_obj;
|
||||
}
|
||||
|
||||
sub _iterate_files {
|
||||
my ( $self ) = @_;
|
||||
my ( $self ) = @_;
|
||||
|
||||
if ( !$self->{fh} ) {
|
||||
my ($fh, $file) = $self->{file_itr}->();
|
||||
@@ -4708,14 +4694,14 @@ sub _iterate_files {
|
||||
next CHUNK;
|
||||
}
|
||||
$ddl =~ s/ \*\/;\Z/;/; # remove end of version comment
|
||||
|
||||
my ($engine) = $ddl =~ m/\).*?(?:ENGINE|TYPE)=(\w+)/;
|
||||
|
||||
if ( !$engine || $self->engine_is_allowed($engine) ) {
|
||||
my $tbl_struct = $self->{TableParser}->parse($ddl);
|
||||
if ( $self->engine_is_allowed($tbl_struct->{engine}) ) {
|
||||
return {
|
||||
db => $self->{db},
|
||||
tbl => $tbl,
|
||||
ddl => $ddl,
|
||||
db => $self->{db},
|
||||
tbl => $tbl,
|
||||
name => $self->{Quoter}->quote($self->{db}, $tbl),
|
||||
ddl => $ddl,
|
||||
tbl_struct => $tbl_struct,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4732,6 +4718,7 @@ sub _iterate_files {
|
||||
sub _iterate_dbh {
|
||||
my ( $self ) = @_;
|
||||
my $q = $self->{Quoter};
|
||||
my $tp = $self->{TableParser};
|
||||
my $dbh = $self->{dbh};
|
||||
PTDEBUG && _d('Getting next schema object from dbh', $dbh);
|
||||
|
||||
@@ -4770,30 +4757,15 @@ sub _iterate_dbh {
|
||||
}
|
||||
|
||||
while ( my $tbl = shift @{$self->{tbls}} ) {
|
||||
my $tbl_status;
|
||||
if ( $self->{filters}->{'engines'}
|
||||
|| $self->{filters}->{'ignore-engines'}
|
||||
|| $self->{keep_tbl_status} )
|
||||
{
|
||||
my $sql = "SHOW TABLE STATUS FROM " . $q->quote($self->{db})
|
||||
. " LIKE \'$tbl\'";
|
||||
PTDEBUG && _d($sql);
|
||||
$tbl_status = $dbh->selectrow_hashref($sql);
|
||||
PTDEBUG && _d(Dumper($tbl_status));
|
||||
}
|
||||
|
||||
if ( !$tbl_status
|
||||
|| $self->engine_is_allowed($tbl_status->{engine}) ) {
|
||||
my $ddl;
|
||||
if ( my $tp = $self->{TableParser} ) {
|
||||
$ddl = $tp->get_create_table($dbh, $self->{db}, $tbl);
|
||||
}
|
||||
|
||||
my $ddl = $tp->get_create_table($dbh, $self->{db}, $tbl);
|
||||
my $tbl_struct = $tp->parse($ddl);
|
||||
if ( $self->engine_is_allowed($tbl_struct->{engine}) ) {
|
||||
return {
|
||||
db => $self->{db},
|
||||
tbl => $tbl,
|
||||
name => $q->quote($self->{db}, $tbl),
|
||||
ddl => $ddl,
|
||||
tbl_status => $tbl_status,
|
||||
tbl_struct => $tbl_struct,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4897,7 +4869,11 @@ sub table_is_allowed {
|
||||
|
||||
sub engine_is_allowed {
|
||||
my ( $self, $engine ) = @_;
|
||||
die "I need an engine argument" unless $engine;
|
||||
|
||||
if ( !$engine ) {
|
||||
PTDEBUG && _d('No engine specified; allowing the table');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$engine = lc $engine;
|
||||
|
||||
@@ -6253,13 +6229,12 @@ sub main {
|
||||
}
|
||||
|
||||
my $schema_iter = new SchemaIterator(
|
||||
dbh => $master_dbh,
|
||||
resume => $last_chunk ? $q->quote(@{$last_chunk}{qw(db tbl)})
|
||||
: "",
|
||||
keep_tbl_status => 1,
|
||||
OptionParser => $o,
|
||||
TableParser => $tp,
|
||||
Quoter => $q,
|
||||
dbh => $master_dbh,
|
||||
resume => $last_chunk ? $q->quote(@{$last_chunk}{qw(db tbl)})
|
||||
: "",
|
||||
OptionParser => $o,
|
||||
TableParser => $tp,
|
||||
Quoter => $q,
|
||||
);
|
||||
|
||||
if ( $last_chunk &&
|
||||
@@ -6334,13 +6309,13 @@ sub main {
|
||||
my $chunk_size_limit = $o->get('chunk-size-limit');
|
||||
my @too_large;
|
||||
foreach my $slave ( @$slaves ) {
|
||||
# get_row_estimate() returns (row_est, index), but
|
||||
# we only need the row_est. Maybe in the future we'll
|
||||
# care what index MySQL will use on a slave.
|
||||
my ($n_rows) = NibbleIterator::get_row_estimate(
|
||||
Cxn => $slave,
|
||||
tbl => $tbl,
|
||||
where => $o->get('where') || "1=1",
|
||||
OptionParser => $o,
|
||||
TableParser => $tp,
|
||||
Quoter => $q,
|
||||
Cxn => $slave,
|
||||
tbl => $tbl,
|
||||
where => $o->get('where'),
|
||||
);
|
||||
PTDEBUG && _d('Table on', $slave->name(),
|
||||
'has', $n_rows, 'rows');
|
||||
|
Reference in New Issue
Block a user