We're having problem with a combination of the core language modules and the Content view using DISTINCT. Here are steps to reproduce it in a minimal 8.3.5 site installation. It must be using MySQL 5.7+ with ONLY_FULL_GROUP_BY enabled.
Enable the Multilingual modules:
Configuration Translation config_translation
Content Translation content_translation
Interface Translation locale
Language language
Navigate to /admin/config/regional/language/detection and deselect URL
Navigate to /admin/config/regional/language and Add Language. Select Danish and wait for the translation files to download
Navigate to /admin/config/regional/language/detection/selected and set the default language to Danish
Navigate to /admin/structure/views/view/content and select Distinct in the query settings (Indstillinger for forespørgsel:Indstillinger / Særskilt)
Select Content (Indhold)
Drupal\Core\Database\DatabaseExceptionWrapper: Exception in Indhold[content]: SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'drupal8.node_field_data.changed' which is not in SELECT list; this is incompatible with DISTINCT: SELECT DISTINCT node_field_data.langcode AS node_field_data_langcode, users_field_data_node_field_data.langcode AS users_field_data_node_field_data_langcode, node_field_data.nid AS nid, users_field_data_node_field_data.uid AS users_field_data_node_field_data_uid FROM {node_field_data} node_field_data INNER JOIN {users_field_data} users_field_data_node_field_data ON node_field_data.uid = users_field_data_node_field_data.uid WHERE (node_field_data.status = 1 OR (node_field_data.uid = 1 AND 1 <> 0 AND 1 = 1) OR 1 = 1) ORDER BY node_field_data.changed DESC LIMIT 50 OFFSET 0; Array ( ) i Drupal\views\Plugin\views\query\Sql->execute() (linje 1488 af /home/ubuntu/deleteme/drupal83/drupal/web/core/modules/views/src/Plugin/views/query/Sql.php).
The issue is related to the use of DISTINCT with ONLY_FULL_GROUP_BY in MySQL 5.7, and the fact that the ORDER BY column is not in the select.
This was performed on Ubuntu 16.04 with the following
Drupal 8.3.5
PHP 7.0.19-1+deb.sury.org~xenial+2
MySQL 5.7.18-0ubuntu0.16.04.1
nginx/1.10.0
Comment | File | Size | Author |
---|---|---|---|
#38 | sql_error_distinct_order_D10-2894688-32.patch | 796 bytes | suramita |
| |||
#31 | sql_error_distinct_order_D8_9_18-2894688-31.patch | 869 bytes | kaloyan.damyanov |
#27 | sql_error_distinct_order_by-2894688-27.patch | 874 bytes | vredko |
#23 | sql_error_distinct_order_by2894688-23.patch | 688 bytes | Dom. |
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedExceptions caused by clicking around in the UI can usually get major priority.
Comment #4
edurenye CreditAttribution: edurenye at ENDPHASYS Technologies commentedComment #5
mvwensen CreditAttribution: mvwensen commentedSame issue over here with MySQL 5.7, temporary fixed it by adding in settings.php:
Comment #6
drupalmind CreditAttribution: drupalmind as a volunteer commentedI am working on triaging this issue at Event, following the instructions in #2474049: [meta] Major issue triage: @fgm is helping as our mentor.
Comment #7
drupalmind CreditAttribution: drupalmind as a volunteer commentedI could not produces this bug on drupal 8.5.x and drupal 8.3.7 and drupal 8.3.5 on mysql 5.5. Unable to update mysql for now.
Comment #10
andypostThis still reproduce on mysql 5.7+ and I bet the same for pgsql
Comment #13
sic CreditAttribution: sic commentedHaving the issue on mysql 5.7 (mamp).
Comment #15
liquidcms CreditAttribution: liquidcms commentedI have this issue with: Drupal 8.8.4 and MySql 5.7.24
At the very least; should Drupal 8 requirements not be corrected where it says Drupal 8 works with MySQL 5.5.3/MariaDB 5.5.20/Percona Server 5.5.8 or higher as it would seem it is not compatible with MySQL 5.7
Comment #16
aiphesafter update php 7.2 to 7.3, I get mysql 5.7 too and th eerror on views content happen.
Comment #17
yfma CreditAttribution: yfma commentedWe are having this issue. Drupal 8.8.8, MySQL 5.7.30
Comment #19
tobiberlinSame here: Drupal 8.9.10 with Configuration Translation, Interface Translation and Language enabled (not Content Translation). When I choose "Distinct" for the view listing nodes it gives this error
Mysql 5.7.26
But this does not only happen with nodes but also with views for other entity types. As soon as "distinct" is set this errors appears. Another example is a view with a custom entity type which references an user in a field. This reference is brought into the view with a relationship. The error message:
SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'drupal8.users_field_data_politician.access' which is not in SELECT list; this is incompatible with DISTINCT
This only happens on my local machine. On our develop/testing instance there is MariaDB 5.5.5 running. On this machine the error does not appear but the "distinct" flag does not lead to reduction of duplicated results.
I found this on Stackoverflow stating that changing the sql-mode for MySQL would solve these problems but at least for me it did not: https://stackoverflow.com/questions/36829911/how-to-resolve-order-by-cla...
Comment #20
anish.a CreditAttribution: anish.a at QBurst commentedSame issue happens for me. As soon as MySQL is upgraded to 5.7, this issue appeared.
Comment #21
anish.a CreditAttribution: anish.a at QBurst commentedComment #22
anish.a CreditAttribution: anish.a at QBurst commentedThis issue is preventing us in upgrading our production environments. Any solution, or pointers to fix this issue?
Comment #23
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedHi !
I had the same issue with the admin/people view on a multilingual environnement. Adding the 'DISTINCT' option while using 'ORDER BY' the created field of user entity gave me the same SQL error as described
Attached is a very simple patch that helped me move on with this issue. Let me see what testbot think of it.
Comment #25
weseze CreditAttribution: weseze as a volunteer commentedUPDATED/DELETED MY ORIGINAL ANSWER because I initially reported the patch was a good fix, but it seems to break other things...
Only thing that seems to fix it for us is to revert to MySQL 5.6 or override the sql_mode with "STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE".
Neither seems like the correct solution. Will report back if we find a better solution.
Comment #27
vredko CreditAttribution: vredko as a volunteer and commentedThanks @Dom. for the patch. Works good, but views where don't use DISTINCT are crash.
New patch attached
Comment #28
vredko CreditAttribution: vredko as a volunteer and commentedComment #29
fjgarlin CreditAttribution: fjgarlin as a volunteer and commentedIn my case, changing the "sql_mode" didn't seem to have any effect (probably due to hosting configuration?) but the patch did indeed work.
I tested views with and without "distinct" and the results were as expected.
MySQL version: 5.7.33-google-log (google cloud mysql).
Marking this as RTBC.
Comment #30
catchIs there an reason not to always add the table alias and column?
Also this could use some test coverage.
Comment #31
kaloyan.damyanov CreditAttribution: kaloyan.damyanov commentedVersion 8.9.18
Comment #33
joseph.olstadworkaround for MySQL 8.0.28 is to do the following:
add this to your settings.php default default db settings
workaround for MySQL 5.7.30 is to add this instead (note: this doesn't work on MySQL 8.0.28, only 5.7.30, also note, this is not necessary if you are using 5.7.31 or 5.7.32 both of which do not require a settings change for whatever reason):
doing this requires no patching.
NOTE: this issue appears to be the same or very similar to #2856270: ORDER BY clause is not in SELECT list errors - inconsistent MySQL defaults some versions allow some dont
Comment #37
mstrelan CreditAttribution: mstrelan at PreviousNext for Service NSW commentedI suspect this is fixed by #3195178: Views table format sorting + distinct results in a SQL error on some db engines, can anyone confirm if this is still applicable?
Comment #38
suramita CreditAttribution: suramita commentedRecreated the patch to apply on Drupal 10 core views.
Comment #39
suramita CreditAttribution: suramita commentedComment #40
LendudeThe question was if this still needs a patch at all, is this still an issue or was this fixed by the issue linked by @mstrelan ?
Comment #41
joseph.olstad