Skip to content

Commit 21d4abf

Browse files
Added support for Oracle Database 23ai statement pipelining.
1 parent 1ede3a4 commit 21d4abf

34 files changed

+2670
-80
lines changed

doc/src/api_manual/async_connection.rst

+31
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ AsyncConnection Methods
166166

167167
Rolls back any pending transaction.
168168

169+
.. method:: AsyncConnection.run_pipeline(pipeline, continue_on_error=False)
170+
171+
Runs all of the operations in the :ref:`pipeline <pipelineobj>` and returns
172+
a list of :ref:`PipelineOpResult Objects <pipelineopresultobjs>`, each
173+
entry corresponding to an operation executed in the pipeline.
174+
175+
The ``continue_on_error`` parameter determines whether operations should
176+
continue to run after an error has occurred. If this parameter is set to
177+
True, then the :attr:`PipelineOpResult.error` attribute will be populated
178+
with an :ref:`_Error <exchandling>` instance which identifies the error
179+
that occurred. If this parameter is set to False, then an exception will be
180+
raised as soon as an error is detected and all subsequent operations will
181+
be terminated. The default value is False.
182+
183+
See :ref:`pipelining` for more information.
184+
185+
.. note::
186+
187+
In this release, pipelining support is experimental and subject to
188+
change.
189+
190+
True pipelining requires Oracle Database 23ai.
191+
192+
When you connect to an older database, operations are sequentially
193+
executed by python-oracledb. Each operation concludes before the next
194+
is sent to the database. There is no reduction in round-trips and no
195+
performance benefit. This usage is only recommended for code
196+
portability such as when preparing for a database upgrade.
197+
198+
.. versionadded:: 2.4.0
199+
169200
.. method:: AsyncConnection.tpc_begin(xid, flags, timeout)
170201

171202
Begins a Two-Phase Commit (TPC) on a global transaction using the specified

doc/src/api_manual/module.rst

+91
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,18 @@ Oracledb Methods
950950

951951
The ``connection_id_prefix`` parameter was added.
952952

953+
.. function:: create_pipeline()
954+
955+
Creates a :ref:`pipeline object <pipelineobjs>` which can be used to
956+
process a set of operations against a database.
957+
958+
.. note::
959+
960+
In this release, pipelining support is experimental and subject to
961+
change.
962+
963+
.. versionadded:: 2.4.0
964+
953965
.. function:: create_pool(dsn=None, pool_class=oracledb.ConnectionPool, \
954966
params=None, min=1, max=2, increment=1, \
955967
connectiontype=oracledb.Connection, \
@@ -2662,6 +2674,85 @@ cx_Oracle 8.3. They are possible values for the ``mode`` parameter of the
26622674
This constant deprecates the ``SYSRAC`` constant that was used in
26632675
cx_Oracle 8.3.
26642676

2677+
.. _pipeline-operation-types:
2678+
2679+
Pipeline Operation Types
2680+
------------------------
2681+
2682+
These constants belong to the enumeration called ``PipelineOpType``. The
2683+
pipelining constants listed below are used to identify the type of operation
2684+
added. They are possible values for the :attr:`PipelineOp.op_type` attribute.
2685+
2686+
.. note::
2687+
2688+
In this release, pipelining support is experimental and subject to change.
2689+
2690+
.. versionadded:: 2.4.0
2691+
2692+
.. data:: oracledb.PIPELINE_OP_TYPE_CALL_FUNC
2693+
2694+
This constant identifies the type of operation as the calling of a stored
2695+
function.
2696+
2697+
This enumerated value can also be identified by
2698+
``oracledb.PipelineOpType.CALL_FUNC``.
2699+
2700+
.. data:: oracledb.PIPELINE_OP_TYPE_CALL_PROC
2701+
2702+
This constant identifies the type of operation as the calling of a stored
2703+
procedure.
2704+
2705+
This enumerated value can also be identified by
2706+
``oracledb.PipelineOpType.CALL_PROC``.
2707+
2708+
.. data:: oracledb.PIPELINE_OP_TYPE_COMMIT
2709+
2710+
This constant identifies the type of operation as the performing of a
2711+
commit.
2712+
2713+
This enumerated value can also be identified by
2714+
``oracledb.PipelineOpType.COMMIT``.
2715+
2716+
.. data:: oracledb.PIPELINE_OP_TYPE_EXECUTE
2717+
2718+
This constant identifies the type of operation as the executing of a
2719+
statement.
2720+
2721+
This enumerated value can also be identified by
2722+
``oracledb.PipelineOpType.EXECUTE``.
2723+
2724+
.. data:: oracledb.PIPELINE_OP_TYPE_EXECUTE_MANY
2725+
2726+
This constant identifies the type of operations as the executing of a
2727+
statement multiple times.
2728+
2729+
This enumerated value can also be identified by
2730+
``oracledb.PipelineOpType.EXECUTE_MANY``.
2731+
2732+
.. data:: oracledb.PIPELINE_OP_TYPE_FETCH_ALL
2733+
2734+
This constant identifies the type of operation as the executing of a
2735+
query and returning all of the rows from the result set.
2736+
2737+
This enumerated value can also be identified by
2738+
``oracledb.PipelineOpType.FETCH_ALL``.
2739+
2740+
.. data:: oracledb.PIPELINE_OP_TYPE_FETCH_MANY
2741+
2742+
This constant identifies the type of operation as the executing of a
2743+
query and returning up to the specified number of rows from the result
2744+
set.
2745+
2746+
This enumerated value can also be identified by
2747+
``oracledb.PipelineOpType.FETCH_MANY``.
2748+
2749+
.. data:: oracledb.PIPELINE_OP_TYPE_FETCH_ONE
2750+
2751+
This constant identifies the type of operation as the executing of a query
2752+
and returning the first row of the result set.
2753+
2754+
This enumerated value can also be identified by
2755+
``oracledb.PipelineOpType.FETCH_ONE``.
26652756

26662757
Database Shutdown Modes
26672758
-----------------------

doc/src/api_manual/pipeline.rst

+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
.. _pipelineobj:
2+
3+
*********************
4+
API: Pipeline Objects
5+
*********************
6+
7+
.. note::
8+
9+
In this release, pipelining support is experimental and subject to change.
10+
11+
See :ref:`pipelining` for more information about pipelining.
12+
13+
.. note::
14+
15+
True pipelining is only available when connected to Oracle Database 23ai.
16+
17+
.. versionadded:: 2.4.0
18+
19+
.. _pipelineobjs:
20+
21+
Pipeline Objects
22+
================
23+
24+
Pipeline objects represent a pipeline used to execute multiple database
25+
operations. A Pipeline object is created by calling
26+
:meth:`oracledb.create_pipeline()`.
27+
28+
.. _pipelinemethods:
29+
30+
Pipeline Methods
31+
----------------
32+
33+
.. method:: Pipeline.add_callfunc(name, return_type, parameters=None, keyword_parameters=None)
34+
35+
Adds an operation that calls a stored PL/SQL function with the given
36+
parameters and return type. When the Pipeline is executed, the
37+
:ref:`PipelineOpResult object <pipelineopresultobjs>` that is returned for
38+
this operation will have the :attr:`~PipelineOpResult.return_value`
39+
attribute populated with the return value of the PL/SQL function if the
40+
call completes successfully.
41+
42+
.. method:: Pipeline.add_callproc(name, parameters=None, keyword_parameters=None)
43+
44+
Adds an operation that calls a stored procedure with the given parameters.
45+
46+
.. method:: Pipeline.add_commit()
47+
48+
Adds an operation that performs a commit.
49+
50+
.. method:: Pipeline.add_execute(statement, parameters=None)
51+
52+
Adds an operation that executes a statement with the given parameters.
53+
54+
Do not use this for queries that return rows. Instead use
55+
:meth:`Pipeline.add_fetchall()`, :meth:`Pipeline.add_fetchmany()`, or
56+
:meth:`Pipeline.add_fetchone()`.
57+
58+
.. method:: Pipeline.add_executemany(statement, parameters)
59+
60+
Adds an operation that executes a statement multiple times with the given
61+
parameter mappings or sequences found in the sequence parameters.
62+
63+
If there are no parameters, the number of iterations can be specified as an
64+
integer instead of needing to provide a list of empty mappings or
65+
sequences.
66+
67+
.. method:: Pipeline.add_fetchall(statement, parameters=None, arraysize=None, rowfactory=None)
68+
69+
Adds an operation that executes a query and returns all of the rows from
70+
the result set. When the Pipeline is executed, the :ref:`PipelineOpResult
71+
object <pipelineopresultobjs>` that is returned for this operation will
72+
have the :attr:`~PipelineOpResult.rows` attribute populated with the list
73+
of rows returned by the query.
74+
75+
The default value for ``arraysize`` is :attr:`defaults.arraysize`.
76+
77+
Internally, this operation's :attr:`Cursor.prefetchrows` size is set to the
78+
value of the explicit or default ``arraysize`` parameter value.
79+
80+
.. method:: Pipeline.add_fetchmany(statement, parameters=None, num_rows=None, rowfactory=None)
81+
82+
Adds an operation that executes a query and returns up to the specified
83+
number of rows from the result set. When the Pipeline is executed, the
84+
:ref:`PipelineOpResult object <pipelineopresultobjs>` that is returned for
85+
this operation will have the :attr:`~PipelineOpResult.rows` attribute
86+
populated with the list of rows returned by the query.
87+
88+
The default value for ``num_rows`` is the value of
89+
:attr:`defaults.arraysize`.
90+
91+
Internally, this operation's :attr:`Cursor.prefetchrows` size is set to the
92+
value of the explicit or default ``num_rows`` parameter, allowing all rows
93+
to be fetched in one :ref:`round-trip <roundtrips>`
94+
95+
Since only one fetch is performed for a query operation, consider adding a
96+
``FETCH NEXT`` clause to the statement to prevent the database processing
97+
rows that will never be fetched, see :ref:`rowlimit`.
98+
99+
.. method:: Pipeline.add_fetchone(statement, parameters=None, rowfactory=None)
100+
101+
Adds an operation that executes a query and returns the first row of the
102+
result set if one exists. When the Pipeline is executed, the
103+
:ref:`PipelineOpResult object <pipelineopresultobjs>` that is returned for
104+
this operation will have the :attr:`~PipelineOpResult.rows` attribute
105+
populated with this row if the query is performed successfully.
106+
107+
Internally, this operation's :attr:`Cursor.prefetchrows` and
108+
:attr:`Cursor.arraysize` sizes will be set to 1.
109+
110+
Since only one fetch is performed for a query operation, consider adding a
111+
``WHERE`` condition or using a ``FETCH NEXT`` clause in the statement to
112+
prevent the database processing rows that will never be fetched, see
113+
:ref:`rowlimit`.
114+
115+
Pipeline Attributes
116+
-------------------
117+
118+
.. attribute:: Pipeline.operations
119+
120+
This read-only attribute returns the list of operations associated with
121+
the pipeline.
122+
123+
.. _pipelineopobjs:
124+
125+
PipelineOp Objects
126+
==================
127+
128+
PipelineOp objects are created by calling the methods in the
129+
:ref:`Pipeline class <pipelineobjs>`.
130+
131+
PipelineOp Attributes
132+
---------------------
133+
134+
.. attribute:: PipelineOp.arraysize
135+
136+
This read-only attribute returns the :ref:`array size <tuningfetch>` that
137+
will be used when fetching query rows with :meth:`Pipeline.add_fetchall()`.
138+
For all other operations, the value returned is 0.
139+
140+
.. attribute:: PipelineOp.keyword_parameters
141+
142+
This read-only attribute returns the keyword parameters to the stored
143+
procedure or function being called by the operation, if applicable.
144+
145+
.. attribute:: PipelineOp.name
146+
147+
This read-only attribute returns the name of the stored procedure or
148+
function being called by the operation, if applicable.
149+
150+
.. attribute:: PipelineOp.num_rows
151+
152+
This read-only attribute returns the number of rows to fetch when
153+
performing a query of a specific number of rows. For all other operations,
154+
the value returned is 0.
155+
156+
.. attribute:: PipelineOp.op_type
157+
158+
This read-only attribute returns the type of operation that is taking
159+
place. See :ref:`pipeline-operation-types` for types of operations.
160+
161+
.. attribute:: PipelineOp.parameters
162+
163+
This read-only attribute returns the parameters to the stored procedure or
164+
function or the parameters bound to the statement being executed by the
165+
operation, if applicable.
166+
167+
.. attribute:: PipelineOp.return_type
168+
169+
This read-only attribute returns the return type of the stored function
170+
being called by the operation, if applicable.
171+
172+
.. attribute:: PipelineOp.rowfactory
173+
174+
This read-only attribute returns the row factory callable function to be
175+
used in a query executed by the operation, if applicable.
176+
177+
.. attribute:: PipelineOp.statement
178+
179+
This read-only attribute returns the statement being executed by the
180+
operation, if applicable.
181+
182+
.. _pipelineopresultobjs:
183+
184+
PipelineOpResult Objects
185+
========================
186+
187+
PipelineOpResult objects are returned in list when calling
188+
:meth:`AsyncConnection.run_pipeline()`. These objects contain the results of
189+
the executed :ref:`PipelineOp objects <pipelineopobjs>` operations.
190+
191+
PipelineOpResult Attributes
192+
---------------------------
193+
194+
.. attribute:: PipelineOpResult.error
195+
196+
This read-only attribute returns the error that occurred when running this
197+
operation. If no error occurred, then the value None is returned.
198+
199+
.. attribute:: PipelineOpResult.operation
200+
201+
This read-only attribute returns the operation associated with the result.
202+
203+
.. attribute:: PipelineOpResult.return_value
204+
205+
This read-only attribute returns the return value of the called PL/SQL
206+
function, if a function was called for the operation.
207+
208+
.. attribute:: PipelineOpResult.rows
209+
210+
This read-only attribute returns the rows that were fetched by the
211+
operation, if a query was executed.

doc/src/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ API Manual
8181
api_manual/async_connection_pool.rst
8282
api_manual/async_cursor.rst
8383
api_manual/async_lob.rst
84+
api_manual/pipeline.rst
8485
api_manual/deprecations.rst
8586

8687
.. toctree::

doc/src/release_notes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ oracledb 2.4.0 (TBD)
1717
Thin Mode Changes
1818
+++++++++++++++++
1919

20+
#) Added support for Oracle Database 23ai :ref:`statement pipelining
21+
<pipelining>`.
2022
#) Fixed bug resulting in a segfault when a closed cursor is bound as a REF
2123
CURSOR
2224
(`issue 368 <https://github.com/oracle/python-oracledb/issues/368>`__).

doc/src/user_guide/appendix_a.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,14 @@ see :ref:`driverdiff` and :ref:`compatibility`.
294294
- No
295295
- Yes
296296
- Yes
297-
* - Concurrent programming with asyncio (see :ref:`asyncio`)
297+
* - Concurrent programming with asyncio (see :ref:`concurrentprogramming`)
298298
- Yes
299299
- No
300300
- No
301+
* - Oracle Database 23ai Pipelining (see :ref:`pipelining`)
302+
- Yes - must use :ref:`asyncio <concurrentprogramming>`
303+
- No
304+
- No
301305
* - End-to-end monitoring and tracing attributes (see :ref:`tracingsql`)
302306
- Yes
303307
- Yes

0 commit comments

Comments
 (0)