Denis Laxalde [Sat, 7 Jan 2023 15:01:36 +0000 (16:01 +0100)]
fix: set rowcount to the first result in executemany(..., returning=True)
Previously, _rowcount was unconditionally set to the overall number of
rows of all queries in executemany() and then reset only upon the first
call to nextset(). In the returning=True case, this lead the rowcount
attribute to be wrong for the first result (i.e. it didn't match the
number of rows that would be returned by .fetchall(), as can be seen in
updated tests).
Now we only set _rowcount to the cumulated number of rows of executed
queries *if* executemany() is not returning (so the value is still
useful, e.g., in to check the number of INSERTed rows):
>>> cur.executemany("INSERT INTO t(r) VALUES (%s)", [(1,), (2,)])
>>> cur.rowcount
2 # number of inserted rows
>>> cur.nextset()
>>> cur.executemany("INSERT INTO t(r) VALUES (%s) RETURNING r", [(1,), (2,)], returning=True)
>>> cur.rowcount
1 # number of rows in the first result set
>>> cur.fetchall()
[(1,)]
>>> cur.nextset()
True
>>> cur.rowcount
1
>>> cur.fetchall()
[(2,)]
>>> cur.nextset()
Besides, the code for processing results from executemany() in
_executemany_gen_no_pipeline() is now similar to that of
_set_results_from_pipeline().
Denis Laxalde [Sun, 8 Jan 2023 14:48:38 +0000 (15:48 +0100)]
refactor: drop superfluous _rowcount reset
In BaseCursor._set_results_from_pipeline() we were resetting _rowcount
if negative. This is superfluous as this code is reached when coming
from _executemany_gen_pipeline() in which we already do
'self._rowcount = 0' early on.
Daniele Varrazzo [Tue, 20 Dec 2022 20:19:23 +0000 (20:19 +0000)]
ci: configure the database to run two-phase-commit tests
We can't use the Github Actions PostgreSQL service because it doesn't
seem possible to configure the server for stored transactions:
- the service yaml definition doesn't take args to pass to run
- we can't overwrite the entry point with a script of ours because the
service starts before actions/checkout
- the postgres image doesn't allow to pass extra parameters to the
server via an env var
Rafi Shamim [Mon, 12 Dec 2022 21:47:33 +0000 (16:47 -0500)]
Run tests against CockroachDB v22.2
v22.2 was released recently, so we can test it. This upgrade revealed a
regression in CRDB that we must workaround
(https://github.com/cockroachdb/cockroach/issues/93739).
This also removes testing for v21.2, since it is no longer supported.
Daniele Varrazzo [Thu, 15 Dec 2022 11:03:44 +0000 (11:03 +0000)]
fix(copy): don't create a row maker on copy
A COPY_OUT result has columns, but no names for the columns. This case
must be handled in cur.description (see #235) but we don't need to
handle it in copy. If we did handle it in copy, we would need a column
name fallback, which we forgot to handle, hence the problem in #460.
Daniele Varrazzo [Tue, 13 Dec 2022 03:05:39 +0000 (03:05 +0000)]
test: ignore error looking for leaks
The leaks counter frequently reports a leak between run 1 and 2 of the
tests. It turns out to be a Decimal Context whose items() method reports
no content. So the problem is related to Python, not psycopg, and it is
not an unbound leak.
Can't reproduce it in CI, but it happens on my laptop, since switching
to Ubuntu 22.04 with Python 3.10.
Daniele Varrazzo [Tue, 13 Dec 2022 04:25:46 +0000 (04:25 +0000)]
fix: don't re-export TypeAlias from _compat module
Pyright special-cases that type and requires to import it from typing or
typing_extensions only (see https://github.com/microsoft/pyright/issues/4197).
Drop conditional dependency on typing_extension and always import
TypeAlias from there.
Daniele Varrazzo [Mon, 17 Oct 2022 02:12:24 +0000 (03:12 +0100)]
feat: add wait_select() function
A few tests show that using select() from Python has a lower overhead.
See #414.
Use this function wherever defined and epoll() is the default select
strategy instead. This is mostly a draft to figure out where this
strategy can be used with success.
Daniele Varrazzo [Mon, 17 Oct 2022 09:42:33 +0000 (10:42 +0100)]
test: add simple test to compare performances in refactoring
This test is inspired to the problem open in #411, and is pretty much a
simple operation in a tight loop. It is used, at the moment, to compare
different ways to test I/O completion strategies with simple and fast
queries under no concurrency.
Daniele Varrazzo [Sun, 27 Nov 2022 14:20:10 +0000 (15:20 +0100)]
perf(c/array): add C implementation of array loader
With this change we get to load an array without the transformer calling
any Python code (if the element loader is a CLoader as well).
We don't need to subclass the binary loader anymore because all the
required info is now taken from the loaded data. As a consequence, we
don't need a BaseArrayLoader anymore.