Skip to content

Commit b1d8d74

Browse files
committed
migration for version id feature, eager_defaults
1 parent 87f7097 commit b1d8d74

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

doc/build/changelog/migration_09.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ rendering::
363363

364364
:ticket:`722`
365365

366+
Server Side Version Counting
367+
-----------------------------
368+
369+
The versioning feature of the ORM (now also documented at :ref:`mapper_version_counter`)
370+
can now make use of server-side version counting schemes, such as those produced
371+
by triggers or database system columns. By providing the value ``False``
372+
to the ``version_id_generator`` parameter, the ORM will fetch the version identifier
373+
from each row at the same time the INSERT or UPDATE is emitted. It is strongly
374+
recommended that this feature be used only on a backend where RETURNING can also
375+
be used, else the additional SELECT statements will add significant performance
376+
overhead. The example provided at :ref:`server_side_version_counter` illustrates
377+
the usage of the Postgresql ``xmin`` system column in order to integrate it with
378+
the ORM's versioning feature.
379+
380+
As a related feature, a new method :meth:`.ValuesBase.return_defaults` has been
381+
added to :class:`.Insert` and :class:`.Update` which in constrast to the
382+
:meth:`.UpdateBase.returning` method provides RETURNING support
383+
that integrates with the "implicit identifier returning" feature and is automatically
384+
utilized or de-utilized depending on backend.
385+
386+
:ticket:`2793`
387+
366388
Behavioral Improvements
367389
=======================
368390

@@ -533,6 +555,28 @@ Generates (everywhere except SQLite)::
533555

534556
:ticket:`2369` :ticket:`2587`
535557

558+
ORM can efficiently fetch just-generated INSERT/UPDATE defaults using RETURNING
559+
-------------------------------------------------------------------------------
560+
561+
The :class:`.Mapper` has long supported an undocumented flag known as
562+
``eager_defaults=True``. The effect of this flag is that when an INSERT or UPDATE
563+
proceeds, and the row is known to have server-generated default values,
564+
a SELECT would immediately follow it in order to "eagerly" load those new values.
565+
Normally, the server-generated columns are marked as "expired" on the object,
566+
so that no overhead is incurred unless the application actually accesses these
567+
columns soon after the flush. The ``eager_defaults`` flag was therefore not
568+
of much use as it could only decrease performance, and was present only to support
569+
exotic event schemes where users needed default values to be available
570+
immediately within the flush process.
571+
572+
In 0.9, as a result of the version id enhancements, ``eager_defaults`` can now
573+
emit a RETURNING clause for these values, so on a backend with strong RETURNING
574+
support in particular Postgresql, the ORM can fetch newly generated default
575+
and SQL expression values inline with the INSERT or UPDATE. The feature takes
576+
place automatically when the target backend and :class:`.Table` supports
577+
"implicit returning".
578+
579+
536580
.. _migration_1068:
537581

538582
Label constructs can now render as their name alone in an ORDER BY

0 commit comments

Comments
 (0)