I recently (in drupal 10.2.4) upgraded Search API from version 1.30 to 1.31, which uses a combination of Search API and Facets (2.07) and a full text search field (exposed filter). After the upgrade, the text search functionality stopped working, and the Drupal log shows the following error related to an SQL syntax error:
Drupal\Core\Database\DatabaseExceptionWrapper while trying to create a temporary table: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'drupaldb.t.word' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by: CREATE TEMPORARY TABLE "db_temporary_66003d7d3c4b1" Engine=MEMORY SELECT DISTINCT "t"."item_id" AS "item_id" FROM (SELECT "t"."item_id" AS "item_id", CASE WHEN "t"."word" LIKE :like_w1 THEN 1 ELSE 0 END AS "w1" FROM "search_api_db_diergeneesmiddelen_index_text_1" "t" LEFT OUTER JOIN "search_api_db_diergeneesmiddelen_index" "t_2" ON t.item_id = t_2.item_id LEFT OUTER JOIN "search_api_db_diergeneesmiddelen_index_language_with_fallback" "t_3" ON t.item_id = t_3.item_id WHERE ("t"."word" LIKE :db_condition_placeholder_0 ESCAPE '\\') AND ("t"."field_name" IN (:db_condition_placeholder_1)) AND (("t_2"."status" = :db_condition_placeholder_2) AND ("t_2"."type" IN (:db_condition_placeholder_3)) AND ("t_3"."value" IN (:db_condition_placeholder_4, :db_condition_placeholder_5))) GROUP BY "t"."item_id") "t"; Array ( [:db_condition_placeholder_0] => %stromease% [:db_condition_placeholder_1] => title [:db_condition_placeholder_2] => 1 [:db_condition_placeholder_3] => diergeneesmiddel [:db_condition_placeholder_4] => nl [:db_condition_placeholder_5] => und [:like_w1] => %stromease% ) in Drupal\search_api_db\Plugin\search_api\backend\Database->getTemporaryResultsTable() (line 2902 of /data/sites/web/drupal/www/modules/contrib/search_api/modules/search_api_db/src/Plugin/search_api/backend/Database.php).
This seems to be a compatibility issue with the SQL mode ONLY_FULL_GROUP_BY, affecting how queries are handled. The error indicates that a column in the query is neither included in the GROUP BY clause nor wrapped in an aggregate function, which ONLY_FULL_GROUP_BY mode does not permit.
Reverting back to Search API version 1.30 eliminates the issue, indicating that the problem is introduced in version 1.31.
I found a related question in the Facets issue queue but believe this issue stems from the query structure in Search API, prompting me to post here.
Has anyone else encountered this problem, or does anyone have suggestions on resolving this issue?
Issue fork search_api-3436123
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
yazzbe commentedComment #3
yazzbe commentedSimilar to the issue detailed here:
https://www.drupal.org/project/facets/issues/3422150
The SQL error in Search API occurs on views with both:
- A "full text search field" (e.g. on the title field)
- Facets linked to that view which have an AND operator (not OR)
Switching the facet operator to OR eliminates the SQL error when using the full text search on title field.
Comment #6
drunken monkeyThanks a lot for reporting this problem!
After a bit of experimenting I was indeed able to reproduce it and write a test for it – I put it into this MR. Didn’t have time to develop a fix yet – the code is unfortunately pretty complex (as are the generated SQL queries), so it’s hard to fix this without breaking other functionality.
Just one note: When reporting SQL errors it’s always very helpful if you note right away which database you are using. But it’s MySQL, correct?
Comment #7
yazzbe commentedMuch appreciated for looking into this.
Yes, the database is MySQL 5.7.44.
Sorry for not mentioning that.
Comment #8
drunken monkeyI think I have it fixed now in the MR. Please test/review!
Incidentally, I now saw that I was actually wondering about the two lines I now deleted back when adding partial matching ten (!) years ago: #1299238-74: Add option for partial matching. The one who wrote them couldn’t explain why they were there but since tests passed either way I decided to keep them in there.
Comment #9
yazzbe commentedI manually applied the change to version 1.31, and that completely resolved the issue for us.
Thank you very, very much for investigating this. I greatly appreciate your efforts in resolving it. It might have been a bit of an edge case. But the mystery of the 2 unknown lines of code is now solved :-)
Thanks!
Comment #10
yazzbe commentedComment #11
drunken monkeyGreat to hear, thanks for testing!
Merged. Thanks again!