MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / yield_per

Method yield_per

lib/sqlalchemy/orm/query.py:1017–1040  ·  view source on GitHub ↗

r"""Yield only ``count`` rows at a time. The purpose of this method is when fetching very large result sets (> 10K rows), to batch results in sub-collections and yield them out partially, so that the Python interpreter doesn't need to declare very large areas of memo

(self, count: int)

Source from the content-addressed store, hash-verified

1015
1016 @_generative
1017 def yield_per(self, count: int) -> Self:
1018 r"""Yield only ``count`` rows at a time.
1019
1020 The purpose of this method is when fetching very large result sets
1021 (> 10K rows), to batch results in sub-collections and yield them
1022 out partially, so that the Python interpreter doesn't need to declare
1023 very large areas of memory which is both time consuming and leads
1024 to excessive memory use. The performance from fetching hundreds of
1025 thousands of rows can often double when a suitable yield-per setting
1026 (e.g. approximately 1000) is used, even with DBAPIs that buffer
1027 rows (which are most).
1028
1029 As of SQLAlchemy 1.4, the :meth:`_orm.Query.yield_per` method is
1030 equivalent to using the ``yield_per`` execution option at the ORM
1031 level. See the section :ref:`orm_queryguide_yield_per` for further
1032 background on this option.
1033
1034 .. seealso::
1035
1036 :ref:`orm_queryguide_yield_per`
1037
1038 """
1039 self.load_options += {"_yield_per": count}
1040 return self
1041
1042 @util.became_legacy_20(
1043 ":meth:`_orm.Query.get`",

Calls

no outgoing calls