Problem/Motivation
The Node module search plugin contains a query that is not portable and not using the database abstraction layer, throwing PDO exception on some non MySQL databases such as SQL Server.
$result = $this->database->queryRange("SELECT n.nid, MAX(sd.reindex) FROM {node} n LEFT JOIN {search_dataset} sd ON sd.sid = n.nid AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0 GROUP BY n.nid ORDER BY MAX(sd.reindex) is null DESC, MAX(sd.reindex) ASC, n.nid ASC", 0, $limit, array(':type' => $this->getPluginId()), array('target' => 'replica'));
Proposed resolution
Rewrite the query to use the database abstraction layer + replace the IS NULL for a CASE WHEN that is universal accross database engines.
Remaining tasks
-
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #1
david_garcia commentedLet's see if this passes on MySQL.
Comment #2
cilefen commentedThere are some 18 tests that load 'search/node' path so I think there is coverage.
Comment #4
david_garcia commentedComment #6
david_garcia commentedComment #7
david_garcia commentedRemoved trailing whitespace.
Comment #10
jhodgdonMoving this to the Search component, which is where we normally work on search-related issues.
Also this needs a test-only patch showing that the existing code fails in some databases, because I believe that all of the existing Core tests currently pass for all databases.
Comment #11
david_garcia commentedBecause the original query does not fail on the core supported databases, there is no way I can make the testbot fail :(
The query that has been modified has wide test coverage so it is sure that it did not break with the rewrite. I feel tempted to remove the +Needs tests tag because I don't understand what can/should be tested here.
Comment #12
jhodgdonWhat database does it fail in then? This is not in the issue summary.
Comment #13
jhodgdonSo... Tests aside (and if it is not a core-supported database, please add details to the issue summary and remove the needs tests tag)...
There is a problem with this query. The original is a range/limit query, and the patch doesn't seem to be? That is a big problem. The code is expecting a limited number of nodes to be in the results, and with this patch it would be unlimited, I believe.
Other than that, it looks OK.
Comment #14
mradcliffe@david_garcia is the maintainer of sqlsrv module in contrib.
Updated issue summary to note that this issue is from SQL Server.
This line adds the range to the query.
Is the same as calling queryRange() in the original?
Comment #15
jhodgdonAh, I missed that. OK, this is probably OK to go then. Correct that there is a lot of test coverage for this already.
Comment #16
david_garcia commentedThanks!
Comment #20
alexpottCommitted 17e425f and pushed to 8.0.x, 8.1.x an 8.2.x. Thanks! Pushed to all branches as the patch applied and there seems no reason not to fix this bug everywhere.
Comment #21
alexpott