From f50d8e9120bba3a450ba6152ed162453eff11618 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 19 Oct 2012 17:14:07 -0600 Subject: [PATCH] Remove TableParser::check_table() privs check (re bug 1036747). --- bin/pt-archiver | 37 ++---------------------------- bin/pt-duplicate-key-checker | 37 ++---------------------------- bin/pt-find | 37 ++---------------------------- bin/pt-heartbeat | 37 ++---------------------------- bin/pt-index-usage | 37 ++---------------------------- bin/pt-kill | 37 ++---------------------------- bin/pt-online-schema-change | 37 ++---------------------------- bin/pt-query-advisor | 37 ++---------------------------- bin/pt-query-digest | 38 +++---------------------------- bin/pt-table-checksum | 37 ++---------------------------- bin/pt-table-sync | 37 ++---------------------------- bin/pt-table-usage | 37 ++---------------------------- bin/pt-upgrade | 37 ++---------------------------- lib/TableParser.pm | 44 ++++-------------------------------- 14 files changed, 31 insertions(+), 495 deletions(-) diff --git a/bin/pt-archiver b/bin/pt-archiver index f17a8dd0..3c6774db 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -1763,42 +1763,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-duplicate-key-checker b/bin/pt-duplicate-key-checker index f3acba29..cf9d9c23 100755 --- a/bin/pt-duplicate-key-checker +++ b/bin/pt-duplicate-key-checker @@ -405,42 +405,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-find b/bin/pt-find index 5cef423c..1f191eaa 100755 --- a/bin/pt-find +++ b/bin/pt-find @@ -1802,42 +1802,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index a55b4680..b7ee3b5b 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -2728,42 +2728,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-index-usage b/bin/pt-index-usage index 4a775959..8dfe7fca 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -3000,42 +3000,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-kill b/bin/pt-kill index 5c77c08a..c9b181f2 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -2678,42 +2678,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 466fae3f..55d025ec 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -2912,42 +2912,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-query-advisor b/bin/pt-query-advisor index d5927de4..0c072d4c 100755 --- a/bin/pt-query-advisor +++ b/bin/pt-query-advisor @@ -5490,42 +5490,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 11370e2f..a2ca9e11 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -38,6 +38,7 @@ BEGIN { MemcachedEvent BinaryLogParser GeneralLogParser + RawLogParser ProtocolParser HTTPProtocolParser ExecutionThrottler @@ -8318,42 +8319,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index c783e2bb..5b6c5263 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -3904,42 +3904,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 60db946d..5273b249 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -2582,42 +2582,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-table-usage b/bin/pt-table-usage index af5d1fde..ac048827 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -5839,42 +5839,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/bin/pt-upgrade b/bin/pt-upgrade index 2aaacf26..62a0af91 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -677,42 +677,9 @@ sub check_table { return 0; } - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + } sub get_engine { diff --git a/lib/TableParser.pm b/lib/TableParser.pm index 9d90de3b..3d2428e0 100644 --- a/lib/TableParser.pm +++ b/lib/TableParser.pm @@ -319,47 +319,11 @@ sub check_table { return 0; } - # Table exists, return true unless we have privs to check. - PTDEBUG && _d('Table exists; no privs to check'); - return 1 unless $args{all_privs}; - - # Get privs select,insert,update. - $sql = "SHOW FULL COLUMNS FROM $db_tbl"; - PTDEBUG && _d($sql); - eval { - $row = $dbh->selectrow_hashref($sql); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - return 0; - } - if ( !scalar keys %$row ) { - # This should never happen. - PTDEBUG && _d('Table has no columns:', Dumper($row)); - return 0; - } - my $privs = $row->{privileges} || $row->{Privileges}; - - # Get delete priv since FULL COLUMNS doesn't show it. - $sql = "DELETE FROM $db_tbl LIMIT 0"; - PTDEBUG && _d($sql); - eval { - $dbh->do($sql); - }; - my $can_delete = $EVAL_ERROR ? 0 : 1; - - PTDEBUG && _d('User privs on', $db_tbl, ':', $privs, - ($can_delete ? 'delete' : '')); - - # Check that we have all privs. - if ( !($privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/ - && $can_delete) ) { - PTDEBUG && _d('User does not have all privs'); - return 0; - } - - PTDEBUG && _d('User has all privs'); + PTDEBUG && _d('Table', $db, $tbl, 'exists'); return 1; + + # No more privs check: + # https://bugs.launchpad.net/percona-toolkit/+bug/1036747 } sub get_engine {