Changes between Initial Version and Version 1 of Ticket #31507


Ignore:
Timestamp:
Apr 22, 2020, 5:44:18 PM (5 years ago)
Author:
Simon Charette
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31507 – Description

    initial v1  
    1 The `QuerySet.exists` method performs optimization by [https://github.com/django/django/blob/67f9d076cfc1858b94f9ed6d1a5ce2327dcc8d0d/django/db/models/sql/compiler.py#L1107-L1115 clearing the select clause], [https://github.com/django/django/blob/67f9d076cfc1858b94f9ed6d1a5ce2327dcc8d0d/django/db/models/sql/query.py#L523-L535 dropping ordering, and limit the number of results to 1 if possible].
     1The `QuerySet.exists` method performs optimization by [https://github.com/django/django/blob/67f9d076cfc1858b94f9ed6d1a5ce2327dcc8d0d/django/db/models/sql/compiler.py#L1107-L1115 clearing the select clause], [https://github.com/django/django/blob/67f9d076cfc1858b94f9ed6d1a5ce2327dcc8d0d/django/db/models/sql/query.py#L523-L535 dropping ordering, and limiting the number of results to 1 if possible].
    22
    33A similar optimization can be applied for combined queries when using `QuerySet.union()` as some query planers (e.g. MySQL) are not smart enough to prune changes down into combined queries.
     
    1212
    1313{{{#!sql
    14 SELECT 1 FROM (SELECT 1 FROM authors WHERE ... LIMIT 1 ... UNION SELECT 1 FROM authors WHERE ... LIMIT 1) LIMIT 1;
     14SELECT 1 FROM (SELECT 1 FROM authors WHERE ... LIMIT 1 UNION SELECT 1 FROM authors WHERE ... LIMIT 1) LIMIT 1;
    1515}}}
    1616
Back to Top