Merge lp:~jmuc/percona-toolkit/float-log-precision into lp:percona-toolkit/2.2

Proposed by Johannes W
Status: Needs review
Proposed branch: lp:~jmuc/percona-toolkit/float-log-precision
Merge into: lp:percona-toolkit/2.2
Diff against target: 116 lines (+49/-4)
2 files modified
bin/pt-table-checksum (+24/-2)
bin/pt-table-sync (+25/-2)
To merge this branch: bzr merge lp:~jmuc/percona-toolkit/float-log-precision
Reviewer Review Type Date Requested Status
Percona Toolkit developers Pending
Review via email: mp+155494@code.launchpad.net

Description of the change

Add new option "--float-log-precision" for alternative rounding algorithm.

This is necessary to compare very large and small floats. See bug #1156214
for details.

To post a comment you must log in.

Unmerged revisions

569. By Johannes W

Add new option "--float-log-precision" for alternative rounding algorithm.

This is necessary to compare very large and small floats. See bug #1156214
for details.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-table-checksum'
--- bin/pt-table-checksum 2013-03-20 17:53:36 +0000
+++ bin/pt-table-checksum 2013-03-26 14:09:22 +0000
@@ -5497,7 +5497,15 @@
5497 $query = join(', ',5497 $query = join(', ',
5498 map { 5498 map {
5499 my $col = $_;5499 my $col = $_;
5500 if ( $col =~ m/\+ 0/ ) {5500 if ( $col =~ m/SIGN/ ) {
5501 my ($real_col) = m/SIGN\(([^\)]+)\)/;
5502 $col .= " AS $real_col";
5503 }
5504 elsif ( $col =~ m/ROUND/ ) {
5505 my ($real_col) = m/ROUND\(([^,]+)/;
5506 $col .= " AS $real_col";
5507 }
5508 elsif ( $col =~ m/\+ 0/ ) {
5501 my ($real_col) = /^(\S+)/;5509 my ($real_col) = /^(\S+)/;
5502 $col .= " AS $real_col";5510 $col .= " AS $real_col";
5503 }5511 }
@@ -5587,6 +5595,7 @@
55875595
5588 my $trim = $o->get('trim');5596 my $trim = $o->get('trim');
5589 my $float_precision = $o->get('float-precision');5597 my $float_precision = $o->get('float-precision');
5598 my $float_log_precision = $o->get('float-log-precision');
55905599
5591 my $tbl_struct = $tbl->{tbl_struct};5600 my $tbl_struct = $tbl->{tbl_struct};
5592 my $ignore_col = $o->get('ignore-columns') || {};5601 my $ignore_col = $o->get('ignore-columns') || {};
@@ -5601,7 +5610,12 @@
5601 $result .= ' + 0';5610 $result .= ' + 0';
5602 }5611 }
5603 elsif ( $float_precision && $type =~ m/float|double/ ) {5612 elsif ( $float_precision && $type =~ m/float|double/ ) {
5604 $result = "ROUND($result, $float_precision)";5613 if ( $float_log_precision ) {
5614 $result = "IF($result = 0, 0, SIGN($result) * ROUND(LOG2(ABS($result)), $float_precision))";
5615 }
5616 else {
5617 $result = "ROUND($result, $float_precision)";
5618 }
5605 }5619 }
5606 elsif ( $trim && $type =~ m/varchar/ ) {5620 elsif ( $trim && $type =~ m/varchar/ ) {
5607 $result = "TRIM($result)";5621 $result = "TRIM($result)";
@@ -11573,6 +11587,14 @@
11573the string representation. If you specify a value of 2, for example, then the11587the string representation. If you specify a value of 2, for example, then the
11574values 1.008 and 1.009 will be rounded to 1.01, and will checksum as equal.11588values 1.008 and 1.009 will be rounded to 1.01, and will checksum as equal.
1157511589
11590=item --float-log-precision
11591
11592Activate an alternative rounding algorithm instead of the simple ROUND()
11593when using L<"--float-precision">. This is necessary to compare very small or
11594large floats. The algorithm is:
11595
11596IF(col = 0, 0, SIGN(col) * ROUND(LOG2(ABS(col)), float_precision))
11597
11576=item --function11598=item --function
1157711599
11578type: string11600type: string
1157911601
=== modified file 'bin/pt-table-sync'
--- bin/pt-table-sync 2013-03-20 17:53:36 +0000
+++ bin/pt-table-sync 2013-03-26 14:09:22 +0000
@@ -4757,7 +4757,12 @@
4757 $result .= ' + 0';4757 $result .= ' + 0';
4758 }4758 }
4759 elsif ( $args{float_precision} && $type =~ m/float|double/ ) {4759 elsif ( $args{float_precision} && $type =~ m/float|double/ ) {
4760 $result = "ROUND($result, $args{float_precision})";4760 if ( $args{float_log_precision} ) {
4761 $result = "IF($result = 0, 0, SIGN($result) * ROUND(LOG2(ABS($result)), $args{float_precision}))";
4762 }
4763 else {
4764 $result = "ROUND($result, $args{float_precision})";
4765 }
4761 }4766 }
4762 elsif ( $args{trim} && $type =~ m/varchar/ ) {4767 elsif ( $args{trim} && $type =~ m/varchar/ ) {
4763 $result = "TRIM($result)";4768 $result = "TRIM($result)";
@@ -4774,7 +4779,16 @@
4774 $query = join(', ',4779 $query = join(', ',
4775 map { 4780 map {
4776 my $col = $_;4781 my $col = $_;
4777 if ( $col =~ m/\+ 0/ ) {4782
4783 if ( $col =~ m/SIGN/ ) {
4784 my ($real_col) = m/SIGN\(([^\)]+)\)/;
4785 $col .= " AS $real_col";
4786 }
4787 elsif ( $col =~ m/ROUND/ ) {
4788 my ($real_col) = m/ROUND\(([^,]+)/;
4789 $col .= " AS $real_col";
4790 }
4791 elsif ( $col =~ m/\+ 0/ ) {
4778 my ($real_col) = /^(\S+)/;4792 my ($real_col) = /^(\S+)/;
4779 $col .= " AS $real_col";4793 $col .= " AS $real_col";
4780 }4794 }
@@ -10501,6 +10515,7 @@
10501 || $o->get('bidirectional')10515 || $o->get('bidirectional')
10502 || 0,10516 || 0,
10503 float_precision => $o->get('float-precision'),10517 float_precision => $o->get('float-precision'),
10518 float_log_precision => $o->get('float-log-precision'),
10504 index_hint => $o->get('index-hint'),10519 index_hint => $o->get('index-hint'),
10505 chunk_index => $o->get('chunk-index'),10520 chunk_index => $o->get('chunk-index'),
10506 chunk_col => $o->get('chunk-column'),10521 chunk_col => $o->get('chunk-column'),
@@ -12006,6 +12021,14 @@
12006the string representation. If you specify a value of 2, for example, then the12021the string representation. If you specify a value of 2, for example, then the
12007values 1.008 and 1.009 will be rounded to 1.01, and will checksum as equal.12022values 1.008 and 1.009 will be rounded to 1.01, and will checksum as equal.
1200812023
12024=item --float-log-precision
12025
12026Activate an alternative rounding algorithm instead of the simple ROUND()
12027when using L<"--float-precision">. This is necessary to compare very small or
12028large floats. The algorithm is:
12029
12030IF(col = 0, 0, SIGN(col) * ROUND(LOG2(ABS(col)), float_precision))
12031
12009=item --[no]foreign-key-checks12032=item --[no]foreign-key-checks
1201012033
12011default: yes12034default: yes

Subscribers

People subscribed via source and target branches