#35918: SQLCompiler.execute_sql result_type CURSOR usage can be minimized
-------------------------------------+-------------------------------------
     Reporter:  Raphael Gaschignard  |                    Owner:  Raphael
         Type:                       |  Gaschignard
  Cleanup/optimization               |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Raphael Gaschignard:

Old description:

> (This refactor is motivated by an ongoing experiment to integrate async
> cursor work into the ORM, by simplifying some cursor management)
>
> In ``django.cdb.models.sql.compiler.Compiler.execute_sql``, we can pass
> in the following result types: ``SINGLE``, ``MULTI``,  ``NO_RESULTS``,
> and ``CURSOR``.
>
> ``execute_sql``'s docstring to that effect does not reflect this.
>
> - ``SINGLE`` returns a single row. It closes the cursor it uses to query.
> - ``MULTI`` returns many rows (wrapped in a cursor iterator). This either
> closes the cursor it uses to query, or returns an iterator that takes
> ownership of the cursor to close the cursor once reading of all the
> results are done.
> - ``NO_RESULTS`` returns nothing. It closes the cursor it uses to query.
> - ``CURSOR`` returns the cursor, without closing the cursor, effectively
> making the caller in charge of closing the cursor
>

> ``CURSOR`` returns an unclosed cursor that has to be manage by the
> caller. In practice, though, apart from a single test usage, Django's
> codebase currently only uses ``CURSOR`` to do one thing: get the number
> of rows, then close the cursor.
>
> To simplify cursor resource management, I have a two-pronged proposal:
> - a new result type, ``ROW_COUNT``, returns the rows and closes the
> cursor for you. This covers all non-test usage of ``CURSOR`` in Django
> currently.
> - ``CURSOR`` is renamed to ``LEAK_CURSOR``, as a way to more strongly
> indicate that you are now in charge of the cursor
>
> Main point here is to reduce the number of places an open cursor might
> come into play.

New description:

 (This refactor is motivated by an ongoing experiment to integrate async
 cursor work into the ORM, by simplifying some cursor management)

 In `django.cdb.models.sql.compiler.Compiler.execute_sql`, we can pass in
 the following result types: `SINGLE`, `MULTI`,  `NO_RESULTS`, and
 `CURSOR`.

 `execute_sql`'s docstring to that effect does not reflect this.

 - `SINGLE` returns a single row. It closes the cursor it uses to query.
 - `MULTI` returns many rows (wrapped in a cursor iterator). This either
 closes the cursor it uses to query, or returns an iterator that takes
 ownership of the cursor to close the cursor once reading of all the
 results are done.
 - `NO_RESULTS` returns nothing. It closes the cursor it uses to query.
 - `CURSOR` returns the cursor, without closing the cursor, effectively
 making the caller in charge of closing the cursor


 `CURSOR` returns an unclosed cursor that has to be manage by the caller.
 In practice, though, apart from a single test usage, Django's codebase
 currently only uses `CURSOR` to do one thing: get the number of rows, then
 close the cursor.

 To simplify cursor resource management, I have a two-pronged proposal:
 - a new result type, `ROW_COUNT`, returns the rows and closes the cursor
 for you. This covers all non-test usage of `CURSOR` in Django currently.
 - `CURSOR` is renamed to `LEAK_CURSOR`, as a way to more strongly indicate
 that you are now in charge of the cursor

 Main point here is to reduce the number of places an open cursor might
 come into play.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019342d038dd-18738b01-4633-4451-be6b-9980a468e051-000000%40eu-central-1.amazonses.com.

Reply via email to