Re: [Django] #34125: Limiting QuerySet crashes on union() with a single non-empty query

16 views
Skip to first unread message

Django

unread,
Oct 27, 2022, 11:46:43 PM10/27/22
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette (added)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report! I attached a regression test which generates the
following SQL on PostgreSQL:
{{{#!sql
(SELECT "queries_number"."id",
"queries_number"."num",
"queries_number"."other_num",
"queries_number"."another_num"
FROM "queries_number"
WHERE "queries_number"."num" <= 0
LIMIT 1)
LIMIT 1;
}}}

Regression in 3d734c09ff0138441dfe0a59010435871d17950f.
Reproduced at de2c2127b66e77a034c01c81753c5c08e651a5b4.

--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 27, 2022, 11:47:22 PM10/27/22
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: Simon
| Charette
Type: Bug | Status: assigned

Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* owner: nobody => Simon Charette
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:4>

Django

unread,
Oct 27, 2022, 11:47:40 PM10/27/22
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "test-34125.diff" added.

Regression test.

--
Ticket URL: <https://code.djangoproject.com/ticket/34125>

Django

unread,
Oct 28, 2022, 1:12:50 AM10/28/22
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:5>

Django

unread,
Oct 28, 2022, 10:37:57 PM10/28/22
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

The patch in its current form should address the reported issue and also
cover other use cases that were not covered when dealing with slicing
combined queries that are sliced themselves.

--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:6>

Django

unread,
Oct 29, 2022, 3:22:21 AM10/29/22
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: Simon
| Charette
Type: Bug | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"c2cc80756b8949cdd87b88bbfdfee698ced441e0" c2cc807]:
{{{
#!CommitTicketReference repository=""
revision="c2cc80756b8949cdd87b88bbfdfee698ced441e0"
Fixed #34125 -- Fixed sliced QuerySet.union() crash on a single non-empty
queryset.

The bug existed since sliced query union was added but was elevated to
query union slices by moving the .exists() optimization to the compiler
in 3d734c09ff0138441dfe0a59010435871d17950f.

Thanks Stefan Hammer for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:7>

Django

unread,
Jul 19, 2024, 2:54:57 AM7/19/24
to django-...@googlegroups.com
#34125: Limiting QuerySet crashes on union() with a single non-empty query
-------------------------------------+-------------------------------------
Reporter: Stefan Hammer | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"9cb8baa0c4fa2c10789c5c8b65f4465932d4d172" 9cb8baa0]:
{{{#!CommitTicketReference repository=""
revision="9cb8baa0c4fa2c10789c5c8b65f4465932d4d172"
Fixed #35559 -- Avoided unnecessary query on sliced union of empty
queries.

While refs #34125 focused on the SQL correctness of slicing of union of
potentially empty queries it missed an optimization opportunity to avoid
performing a query at all when all queries are empty.

Thanks Lucidiot for the report.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34125#comment:8>
Reply all
Reply to author
Forward
0 new messages