Bug #26051 XML: ExtractValue() returns wrong results for boolean() XPath test
Submitted: 3 Feb 2007 18:23 Modified: 21 Jul 2008 9:38
Reporter: Marcin Kurzyna Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: XML functions Severity:S3 (Non-critical)
Version:5.1.14 OS:Linux (Linux)
Assigned to: Alexander Barkov CPU Architecture:Any
Tags: ExtractValue, XML, XPath

[3 Feb 2007 18:23] Marcin Kurzyna
Description:
The boolean() XPath test returns false for all tests where node count > 1. According to http://www.w3.org/TR/xpath#section-Boolean-Functions boolean() should return true for non empty node-sets.

This is tested on server with applyed patch for bug #24747 
(XML node axes access).

How to repeat:
mysql> set @xml = '<r><n id="1">v</n><n id="2">v</n></r>';
Query OK, 0 rows affected (0.00 sec)

Ex1: Error for more then one node in result-set:
----------------------------------------------------------------

mysql> SELECT ExtractValue(@xml,'boolean(//n)') AS WrongResult;
+--------------+
| WrongResult |
+--------------+
| 0            |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT ExtractValue(@xml,'count(//n)') AS CorrectResult;
+---------------+
| CorrectResult |
+---------------+
| 2             |
+---------------+
1 row in set (0.00 sec)

Ex2: Correct for one node in result-set:
----------------------------------------------------------------

mysql> SELECT ExtractValue(@xml,'boolean(//n[@id=1])') AS CorrectResult;
+---------------+
| CorrectResult |
+---------------+
| 1             |
+---------------+
1 row in set (0.00 sec)

mysql> SELECT ExtractValue(@xml,'count(//n[@id=1])') AS CorrectResult;
+---------------+
| CorrectResult |
+---------------+
| 1             |
+---------------+
1 row in set (0.00 sec)

Ex3: Correct for no node in result-set:
----------------------------------------------------------------

mysql> SELECT ExtractValue(@xml,'boolean(//n[@id=3])') AS CorrectResult;
+---------------+
| CorrectResult |
+---------------+
| 0             |
+---------------+
1 row in set (0.00 sec)

mysql> SELECT ExtractValue(@xml,'count(//n[@id=3])') AS CorrectResult;
+---------------+
| CorrectResult |
+---------------+
| 0             |
+---------------+
1 row in set (0.00 sec)
[5 Feb 2007 10:01] Sveta Smirnova
Thank you for the report.

Verified as described on Linux using last developers sources.
[4 Oct 2007 9:27] Alexander Barkov
The second part of this problem is that boolean cast form strings
does not work well:

mysql> SELECT ExtractValue('<r></r>','boolean("00")') as WrongResult;
+-------------+
| WrongResult |
+-------------+
| 0           |
+-------------+
1 row in set (2.17 sec)

mysql> SELECT ExtractValue('<r></r>','boolean("11")') as CorrectResult;
+---------------+
| CorrectResult |
+---------------+
| 1             |
+---------------+
1 row in set (1.09 sec)

It must work this way:

"a string is true if and only if its length is non-zero"

so both queries must return 1.
[4 Oct 2007 9:44] 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/34883

ChangeSet@1.2569, 2007-10-04 14:40:27+05:00, bar@mysql.com +3 -0
  Bug#26051 XML: ExtractValue() returns wrong results for boolean() XPath test
  Problem: boolean cast didn't work well in some cases:
  - node sets consisting of more than one nodes
  - strings
  Fix: making boolean cast work accoring to XPath specifications:
  - return true for any non-empty node sets
  - return true for any non-empty strings
[27 Mar 2008 11:03] 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/44505

ChangeSet@1.2574, 2008-03-27 14:57:06+04:00, bar@mysql.com +3 -0
  Bug#26051 XML: ExtractValue() returns wrong results for boolean() XPath test
  Problem: boolean cast didn't work well in some cases:
  - node sets consisting of more than one nodes
  - strings
  Fix: making boolean cast work accoring to XPath specifications:
  - return true for any non-empty node sets
  - return true for any non-empty strings
  - return 0 for NULL strings
[1 Apr 2008 10:44] Alexander Barkov
Pushed into 5.1.24-engines
[18 Jul 2008 8:34] Alexander Barkov
Merged into bzr mysql-6.0.7
[21 Jul 2008 9:38] Jon Stephens
Documented bugfix in the 5.1.24 and 6.0.7 changelogs. Noted issues in XML Functions section of 5.1 and 6.0 Manual. Closed.
[14 Sep 2008 1:58] Bugs System
Pushed into 6.0.6-alpha  (revid:sp1r-bar@mysql.com/bar.myoffice.izhnet.ru-20080327105706-41158) (version source revid:hakan@mysql.com-20080716160034-sdexuyp3qow7zlc6) (pib:3)