1
0
mirror of https://github.com/django/django.git synced 2025-02-08 16:35:17 +00:00

Fixed #31331 -- Switched MySQL to group by selected primary keys.

MySQL 5.7.15 supports group by functional dependences so there is no
need to special case group by main table primary key anymore and
special case the ONLY_FULL_GROUP_BY sql mode.
This commit is contained in:
Simon Charette 2022-11-05 12:41:56 -04:00 committed by Mariusz Felisiak
parent 967f8750ab
commit 041551d716
2 changed files with 4 additions and 14 deletions

View File

@ -6,7 +6,7 @@ from django.utils.functional import cached_property
class DatabaseFeatures(BaseDatabaseFeatures):
empty_fetchmany_value = ()
allows_group_by_pk = True
allows_group_by_selected_pks = True
related_fields_match_type = True
# MySQL doesn't support sliced subqueries with IN/ALL/ANY/SOME.
allow_sliced_subqueries_with_in = False
@ -109,18 +109,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"update.tests.AdvancedTests.test_update_ordered_by_m2m_annotation",
},
}
if "ONLY_FULL_GROUP_BY" in self.connection.sql_mode:
skips.update(
{
"GROUP BY optimization does not work properly when "
"ONLY_FULL_GROUP_BY mode is enabled on MySQL, see #31331.": {
"aggregation.tests.AggregateTestCase."
"test_aggregation_subquery_annotation_multivalued",
"annotations.tests.NonAggregateAnnotationTestCase."
"test_annotation_aggregate_with_m2o",
},
}
)
if self.connection.mysql_is_mariadb and (
10,
4,

View File

@ -235,7 +235,9 @@ class SQLCompiler:
expressions = [
expr
for expr in expressions
if expr in pks or getattr(expr, "alias", None) not in aliases
if expr in pks
or expr in having
or getattr(expr, "alias", None) not in aliases
]
return expressions