Bug #41368 --replace_regex does not work as expected
Submitted: 10 Dec 2008 18:07 Modified: 2 Mar 2009 18:24
Reporter: Hakan Küçükyılmaz Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Paul DuBois CPU Architecture:Any

[10 Dec 2008 18:07] Hakan Küçükyılmaz
Description:
--replace_regex does not work on a multi-column row.

This is either a documentation bug or mysql-test-run.pl bug.
See --replace_regex documentation
http://dev.mysql.com/doc/mysqltest/en/mysqltest-commands.html

In the output from the next statement, find strings that match pattern (a regular expression) and replace them with replacement. Each instance of a string in the line that matches the pattern is replaced. Matching is case sensitive by default. Specify the optional i modifier to cause matching to be case insensitive. 

How to repeat:
hakan@lu0011:~/work/mysql/mysql-6.0-falcon-team/mysql-test$ more t/tab_test.test

# This does not work, because we have two columns.
--replace_regex /1[[:space:]]2/replace_regex works/
SELECT 1, 2 FROM DUAL;

# This works, because we have one column.
--replace_regex /1[[:space:]]2/replace_regex with space works/
SELECT '1 2' FROM DUAL;

# This works, because we have one column.
# Note that the space between 1 and 2 should be a tab.
--replace_regex /1[[:space:]]2/replace_regex with tab works/
SELECT '1       2' FROM DUAL;

# In this case only the tab within the columns are replaced and
# not the whole row.
# Note that the space between 1 and 2 - 3 and 4 should be a tab.
--replace_regex /[[:space:]]/replace_regex with tab with two columns works/
SELECT '1       2', '3  4' FROM DUAL;

Suggested fix:
Either fix --replace_regex to work on whole row or fix documentation to mention that --replace_regex works only on each column of the result set.
[10 Dec 2008 21:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/61284

2932 Hakan Kuecuekyilmaz	2008-12-10
      * Workaround for Bug#41368 --replace_regex does
      not work as expected.
      
      * Fix for Bug #40636 falcon_bug_28095 test fails
      with "Server failed to restart".
      
      * Fix for Bug #41303 Using global variable makes mysql-test-run
      test fail.
      
      * Fixed a gcc warning in mysys/stacktrace.c.
      
      * Made falcon_unicode.test a --big-test test.
[10 Dec 2008 21:56] Hakan Küçükyılmaz
Just pushed a workaround to a test case, which suffers from this bug.
[11 Dec 2008 6:36] Sveta Smirnova
Thank you for the report.

I got a bit different results than you describe:

=====mysql-6.0=====
=====bug41368=====
SELECT 1, 2 FROM DUAL;
1       2
1       2
SELECT 'replace_regex with space works' FROM DUAL;
replace_regex with space works
replace_regex with space works
SELECT 'replace_regex with tab works' FROM DUAL;
replace_regex with tab works
replace_regex with tab works
SELECTreplace_regex with tab with two columns works'1replace_regex with tab with two columns works2',replace_regex with tab with two columns works'3replace_regex with tab with two columns works4'replace_regex with tab with two columns worksFROMreplace_regex with tab with two columns worksDUAL;
1replace_regex with tab with two columns works2 3replace_regex with tab with two columns works4
1replace_regex with tab with two columns works2 3replace_regex with tab with two columns works4

$cat bug41368.test
--replace_regex /1[[:space:]]2/replace_regex works/
SELECT 1, 2 FROM DUAL;

--replace_regex /1[[:space:]]2/replace_regex with space works/
SELECT '1 2' FROM DUAL;

--replace_regex /1[[:space:]]2/replace_regex with tab works/
SELECT '1	2' FROM DUAL;

--replace_regex /[[:space:]]/replace_regex with tab with two columns works/
SELECT '1 2', '3	4' FROM DUAL; 

$perl --version

This is perl, v5.8.6 built for i386-linux-thread-multi

Please check if you really get same results.
[11 Dec 2008 9:06] Hakan Küçükyılmaz
Your results show the problem. In the first output the tab between the two columns is not replaced. In the last output the tab is only replaced within the column but not between the columns.
[11 Dec 2008 14:19] Bugs System
Pushed into 6.0.9-alpha  (revid:hky@sun.com-20081210214553-mfx2mfwcvnga1aig) (version source revid:hky@sun.com-20081210214553-mfx2mfwcvnga1aig) (pib:5)
[11 Dec 2008 15:17] Sveta Smirnova
Thank you for the feedback.

Verified as described: replace_regex does not replace values in some results, although documenation says " replace_regex /pattern/replacement/[i] ...

In the output from the next statement, find strings that match pattern (a regular expression) and replace them with replacement. "
[26 Feb 2009 11:52] Patrick Crews
After discussion with Hakan, we agree that this is a documentation bug.

--replace_regex works fine within columns of data, but not within an entire row of multiple column.  It doesn't look for patterns that span multiple columns (ie it doesn't combine the total data of all columns), it only finds matches within a single column at a time (though multiple columns might have matching patterns).  The documentation should be more explicit about this working constraint.
[2 Mar 2009 18:24] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.