Utility functions to find "bad" XPath user/miker/pg-upgrade-fixes
authorMike Rylander <mrylander@gmail.com>
Mon, 10 Jan 2022 14:29:01 +0000 (09:29 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 10 Jan 2022 14:54:45 +0000 (09:54 -0500)
commit2d8f5c4faeedfdec4ec41888c15755871ca4d54f
treedc2f61bc5e6e0444b94d96852d33a2cebd65ff13
parentd44ea191f7920a5679da3cf3d703d64db25dcf70
Utility functions to find "bad" XPath

Evergreen community testing has identified two specific changes to how
XPath is processed in PostgreSQL 10 and later.  Both of these changes
came about as a result of improved PostgreSQL standards conformance with
regard to how XML data should be handled in SQL.

The first change in PostgreSQL is related to how XML is handled by the
XPath processor and requires that Evergreen use DOCUMENT oriented, rather
than CONTENT oriented XPath expressions.  This means that XPath expressions
cannot begin with "./" or "*" because in DOCUMENT mode there is no context
node that can be assumed.  These expressions must be adjusted, and this
commit provides a utitily function that attempts to detect user-supplied
XPath expressions that should be considered.

The second change is a side effect of the first, related to how the results
of global XPath expressions are assembled when processed in DOCUMENT mode
rather than CONTENT mode.  In some situations, expressions will match a
node and its parent, and they will both show up in the result set as
separate values.  The effect for Evergreen is duplicated content in many
cases.  These expressions can take many forms, but a common pattern is
a whole-document search with one level of tests, no element name test, and
an attribute value test.  This commit provides a function that attempts
to find expressions matching this pattern.

Finally, these functions are built on top of a general function that
takes two regexps, one for the field name and one for the field content,
and returns the schema and table name, column data, and primary key value
of matching rows, which may be useful for other content pattern matching
needs in the future.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.data.find-bad-xpath.sql [new file with mode: 0644]