]>
git.ipfire.org Git - thirdparty/psycopg.git/log
Daniele Varrazzo [Thu, 7 Jan 2021 04:04:39 +0000 (05:04 +0100)]
Added text copy implementation in C
Daniele Varrazzo [Wed, 6 Jan 2021 23:49:05 +0000 (00:49 +0100)]
Accumulate lines into a buffer to send copy data in larger chunks
Daniele Varrazzo [Sat, 2 Jan 2021 21:45:06 +0000 (22:45 +0100)]
Work around __weakref__ + __slots__ + Generics bug on Python 3.6
See bug https://bugs.python.org/issue41451
Daniele Varrazzo [Sat, 2 Jan 2021 13:52:27 +0000 (14:52 +0100)]
Define better registering, importing, subclassing adapters.
- The C dumpers cannot be subclassed. Subclassing from Python makes
difficult to use the c fast path, unless doing relatively expensive
checks.
- C optimised classes are chosen on registration. The types module only
exposes the Python objects, so they can be documented and subclassed.
Override adapter in the respective type modules
This way they are properly exposed to the rest of the Python code.
Note that it will need some trickery to be able to subclass them in
Python: overridden adapter will need the C fast path bypassed if
subclassing is detected.
Export C int subclasses dumpers to Python
Added guards to allow subclassing C adapters
Not sure this is the way to go though. Subclassing might be a rare
enough case to just make the classes final.
The check is implemented at instance level: it would be more efficient
to implement it at class level, however I don't know how to store class
attribute or implement metaclasses in Cython.
Don't make C types subclassable
C types are no more exposed in types, so they won't get subclassed by
final users.
Checking for subclass in adaptation is expensive, so I'd rather not do
it.
Check if a class has a matching optimised class (with the same name) at
registration time.
Daniele Varrazzo [Sat, 2 Jan 2021 02:47:06 +0000 (03:47 +0100)]
Dropped use of decorator to register builtin adapters
Although the registration function is unwieldy already, it's good to get
more flexibility in when it should happen.
It also convinced me that flat is better than nested so the
psycopg3.types can be the facade for all the type-related objects.
More important, it should allow to override certain objects with C
equivalents.
Daniele Varrazzo [Fri, 1 Jan 2021 20:58:01 +0000 (21:58 +0100)]
Added int4 C dumper
Daniele Varrazzo [Fri, 1 Jan 2021 19:19:39 +0000 (20:19 +0100)]
Added C float dumpers
Daniele Varrazzo [Fri, 1 Jan 2021 17:51:32 +0000 (18:51 +0100)]
Added C helper for binary copy formatting
Daniele Varrazzo [Fri, 1 Jan 2021 17:46:22 +0000 (18:46 +0100)]
Create the waiting selector only after the first wait
Sometimes there is no need to wait at all, if the generator exits on the
first result. It happens especially in copy.
Daniele Varrazzo [Thu, 31 Dec 2020 19:25:57 +0000 (20:25 +0100)]
Copy objects refactoring to isolate the row format function
Daniele Varrazzo [Thu, 31 Dec 2020 18:59:22 +0000 (19:59 +0100)]
Added c interface to dumpers
Daniele Varrazzo [Thu, 31 Dec 2020 03:53:19 +0000 (04:53 +0100)]
Global replace of src -> cls params and attribs
Daniele Varrazzo [Thu, 31 Dec 2020 03:27:49 +0000 (04:27 +0100)]
Added AdaptersMap.get_loader(), get_dumper() methods
Internal refactoring to keep separate maps for different formats rather
than using tuples as keys, both in the AdaptersMap and Transformer.
Dumper.src renamed to cls.
Daniele Varrazzo [Wed, 30 Dec 2020 22:34:23 +0000 (23:34 +0100)]
Using new types registration system on the C implementation too
Daniele Varrazzo [Wed, 30 Dec 2020 21:52:18 +0000 (22:52 +0100)]
Loder and Dumper text/binary decorator unified as "builtin"
Allow registration by builtin name too and on several arguments for
terseness.
Daniele Varrazzo [Wed, 30 Dec 2020 21:22:27 +0000 (22:22 +0100)]
Dropped unneeded assignment
Daniele Varrazzo [Wed, 30 Dec 2020 21:02:02 +0000 (22:02 +0100)]
Dropped format parameter from register
Now the loaders/dumper declare their format themselves.
Daniele Varrazzo [Wed, 30 Dec 2020 19:30:59 +0000 (20:30 +0100)]
Added guard for lazy import to avoid the import statement
I'm mot so sure it's always so fast to re-import.
Daniele Varrazzo [Wed, 30 Dec 2020 19:27:56 +0000 (20:27 +0100)]
Added Loader.format and Dumper.format
Daniele Varrazzo [Wed, 30 Dec 2020 17:53:19 +0000 (18:53 +0100)]
Don't convert fformat and binary_tuples to Format in C pq wrapper
Daniele Varrazzo [Wed, 30 Dec 2020 17:23:06 +0000 (18:23 +0100)]
Fixed binary copy with empty content
Daniele Varrazzo [Wed, 30 Dec 2020 15:31:13 +0000 (16:31 +0100)]
Dropped async/sync code duplication using high level generators
Daniele Varrazzo [Wed, 30 Dec 2020 03:03:06 +0000 (04:03 +0100)]
Use slots on PostgresQuery object
Daniele Varrazzo [Wed, 30 Dec 2020 02:53:23 +0000 (03:53 +0100)]
Fast-path in query preparation to skip expensive isinstance
Daniele Varrazzo [Wed, 30 Dec 2020 02:30:10 +0000 (03:30 +0100)]
Added slots on cursor
Daniele Varrazzo [Wed, 6 Jan 2021 23:55:56 +0000 (00:55 +0100)]
Added backer @MaterializeInc. Thank you :)
Daniele Varrazzo [Tue, 29 Dec 2020 17:47:45 +0000 (18:47 +0100)]
Merge branch 'c-optimise'
Daniele Varrazzo [Tue, 29 Dec 2020 17:09:02 +0000 (18:09 +0100)]
Make testable, and test, the different waiting implementation
Also fixed segfault calling flush on a closed connection.
Daniele Varrazzo [Tue, 29 Dec 2020 03:03:34 +0000 (04:03 +0100)]
Added epoll-based wait() implementation
Only used if the EpollSelector would (i.e. epoll is available and it's
the best thing on the menu). Saves noticeable time over the
EpollSelector as there's less Python stuff going on and can use ONESHOT
+ MOD_CTL.
Daniele Varrazzo [Tue, 29 Dec 2020 04:16:44 +0000 (05:16 +0100)]
More tweaks to the Transformer C code
Daniele Varrazzo [Mon, 28 Dec 2020 04:28:01 +0000 (05:28 +0100)]
Tweaking generators.execute C code
Daniele Varrazzo [Sun, 27 Dec 2020 23:20:47 +0000 (00:20 +0100)]
Use the C api to create memoryview objects
Daniele Varrazzo [Sun, 27 Dec 2020 22:55:18 +0000 (23:55 +0100)]
Use cython type declarations for bytes too
Daniele Varrazzo [Sun, 27 Dec 2020 22:25:48 +0000 (23:25 +0100)]
Use cython type declaration rather than python annotation for int
It gives directly a c variable.
Daniele Varrazzo [Sun, 27 Dec 2020 21:26:20 +0000 (22:26 +0100)]
Don't use enums for libpq arguments
We might want to have speed there. Enums can be returned from high-level
objects such as the Connection.info object to be implemented.
Daniele Varrazzo [Mon, 28 Dec 2020 03:38:28 +0000 (04:38 +0100)]
Added guard to avoid failure on __del__ of unborn connection
Daniele Varrazzo [Mon, 28 Dec 2020 03:25:40 +0000 (04:25 +0100)]
Set public module for PQerror
Daniele Varrazzo [Sun, 27 Dec 2020 16:56:18 +0000 (17:56 +0100)]
Module psycopg3_c.pq_cython renamed to psycopg3_c.pq
psycopg3_c files reorganised in directories. Still unable to split and
localise pxd files, but now it's already cleaner.
Travis keeps failing in funny ways, so skipping fork tests (they pass ok
locally).
Daniele Varrazzo [Sun, 27 Dec 2020 02:18:37 +0000 (03:18 +0100)]
Fixed comment after adapters refactoring
Daniele Varrazzo [Sun, 27 Dec 2020 02:09:05 +0000 (03:09 +0100)]
Avoid catching exceptions for dict lookup in C
Daniele Varrazzo [Sun, 27 Dec 2020 01:45:58 +0000 (02:45 +0100)]
Further use of the C api to reduce some cython checking
Daniele Varrazzo [Sun, 27 Dec 2020 00:46:52 +0000 (01:46 +0100)]
More efficient rows loading
Iterate by columns first, so that choices regarding the loader can be
done only once instead of once per row.
Daniele Varrazzo [Sat, 26 Dec 2020 23:28:29 +0000 (00:28 +0100)]
Added Transformer.load_rows()
There is some good optimisation to be had moving in C the two loops.
Daniele Varrazzo [Sat, 26 Dec 2020 22:12:02 +0000 (23:12 +0100)]
Some C optimisation of the Transformer object
Don't use a list of 2-tuples to set types, use two lists of scalars.
Daniele Varrazzo [Sat, 26 Dec 2020 20:55:32 +0000 (21:55 +0100)]
Optimise access to PGresult data
Access the underlying data structure instead of using the libpq
functions.
We shouldn't, but the speed increase is noticeable.
Daniele Varrazzo [Sat, 26 Dec 2020 18:40:08 +0000 (19:40 +0100)]
Internal functions moved out of cython class
Avoid a vpointer lookup for them
Daniele Varrazzo [Sat, 26 Dec 2020 18:09:17 +0000 (19:09 +0100)]
Release the gil around the exec/send libpq functions
Daniele Varrazzo [Sat, 26 Dec 2020 18:07:38 +0000 (19:07 +0100)]
Added guard for negative numbers in load_row
Also added a reminder to review the C implementation for performance.
Daniele Varrazzo [Sun, 27 Dec 2020 16:12:51 +0000 (17:12 +0100)]
Added repr of several objects
Show the underlying connection basic identification and status.
Daniele Varrazzo [Sun, 27 Dec 2020 04:18:27 +0000 (05:18 +0100)]
Raise a resource warning if a connection is deleted while open
Daniele Varrazzo [Sat, 26 Dec 2020 00:08:32 +0000 (01:08 +0100)]
Adaptation context reworked
Don't use a sequence of dictionaries, but a single copy-on-write
structure, which is cheaper to explore.
Added a protocol representing all the objects that can be used as
adaptation context in order to avoid cascades of isinstance.
The difference in behaviour is that changing global adapters doesn't
affect already created connections which had been customised, and likely
customised cursors are not affected by global and connection changes.
The utility of the previous behaviour doesn't seem anything on which
people would build an empire on, the new behaviour is good as well.
Daniele Varrazzo [Fri, 25 Dec 2020 18:40:37 +0000 (19:40 +0100)]
Dropped unused Transformer attribute
Daniele Varrazzo [Fri, 25 Dec 2020 18:17:22 +0000 (19:17 +0100)]
Dropped tox from dev requirements
Daniele Varrazzo [Fri, 25 Dec 2020 17:43:56 +0000 (18:43 +0100)]
Prepared statements management moved to a purpose class
Daniele Varrazzo [Fri, 25 Dec 2020 14:20:23 +0000 (15:20 +0100)]
The function to maintain prepared statements is no more a generator
Just generate the necessary statements, yield will happen only if
necessary.
Daniele Varrazzo [Fri, 25 Dec 2020 14:05:59 +0000 (15:05 +0100)]
Dropped "unknown loader", use the text loader for everything
Register the C implementation on all the types where it is useful.
Daniele Varrazzo [Fri, 25 Dec 2020 12:14:34 +0000 (13:14 +0100)]
Implement fetch* not in term of iter
Shave some time on lists reallocation, but especially avoid going
through __aiter__ on async, because profiling showed some 20% of the
time spent there.
This makes me rethink the entire giving async interface for things that are
already on the client side. Feels like that, in order to implement server-side
cursor, we are shedding speed on the common use of async connections.
Daniele Varrazzo [Fri, 25 Dec 2020 03:13:23 +0000 (04:13 +0100)]
Exclude .pyx files from sdist package
This way install only depends on the .c files compiled by us.
Daniele Varrazzo [Fri, 25 Dec 2020 03:01:13 +0000 (04:01 +0100)]
Merge branch 'ctypes-reorganisation'
Daniele Varrazzo [Mon, 21 Dec 2020 01:39:09 +0000 (02:39 +0100)]
Fixed typos in cython
Daniele Varrazzo [Mon, 21 Dec 2020 00:59:57 +0000 (01:59 +0100)]
Dropped 'impl' alias for libpq in cython
Daniele Varrazzo [Mon, 21 Dec 2020 00:49:06 +0000 (01:49 +0100)]
psycopg3_c packages moved closer to where they are used
Things were compiling well because everything goes into the same namespace.
Daniele Varrazzo [Mon, 21 Dec 2020 00:27:10 +0000 (01:27 +0100)]
Other psycopg3_c.pq_cython objects split in modules
Daniele Varrazzo [Mon, 21 Dec 2020 00:21:19 +0000 (01:21 +0100)]
Further PGconn code moving and stricter declarations
Daniele Varrazzo [Sun, 20 Dec 2020 23:58:11 +0000 (00:58 +0100)]
PGconn code moved to pq directory
Daniele Varrazzo [Sun, 20 Dec 2020 23:49:34 +0000 (00:49 +0100)]
Dropped __init__ file from types, which is not a package
Daniele Varrazzo [Sun, 20 Dec 2020 23:48:43 +0000 (00:48 +0100)]
Use a strict PGconn type on Escaping.__init__ definition definition
Daniele Varrazzo [Sun, 20 Dec 2020 23:36:19 +0000 (00:36 +0100)]
Escaping code moved to psycopg3_c/pq dir
Daniele Varrazzo [Sun, 20 Dec 2020 18:51:02 +0000 (19:51 +0100)]
libpq cython declarations moved to psycopg3_c/pq package
Daniele Varrazzo [Fri, 25 Dec 2020 02:46:16 +0000 (03:46 +0100)]
Merge branch 'prepared-statements'
Daniele Varrazzo [Fri, 25 Dec 2020 02:44:56 +0000 (03:44 +0100)]
Added note to remember to review preparation in executemany
Daniele Varrazzo [Fri, 25 Dec 2020 02:10:47 +0000 (03:10 +0100)]
Added documentation for prepared statements
Daniele Varrazzo [Thu, 24 Dec 2020 04:00:27 +0000 (05:00 +0100)]
PostgresQuery const initialisation moved to the class
Daniele Varrazzo [Thu, 24 Dec 2020 03:42:41 +0000 (04:42 +0100)]
Use text oid for text/unknown types on PG 9.6
This creates a difference between PG 96 and >= 10 as in the latter less
casts are required. However unknown oid cannot be used to prepare queries
in PG 9.6.
Daniele Varrazzo [Wed, 23 Dec 2020 02:35:00 +0000 (03:35 +0100)]
Added first implementation of prepared statements support
Daniele Varrazzo [Tue, 22 Dec 2020 17:09:34 +0000 (18:09 +0100)]
Implement connection/cursor procedures as generators
Generators are common to both sync and async code so there is much less
code duplication, which will be useful in the light of doing more
complex things such as prepared transactions.
As a side effect of the refactoring, operations on closed connections
are raised as OperationalError rather than InterfaceError because
connection closure may depend on external factors.
Dropped fd from PQGen stream: the having the fd in the middle of the
`Ready` values made more difficult to chain more than one operation in
the same generator. The fd is not passed as extra parameter.
Daniele Varrazzo [Wed, 23 Dec 2020 21:02:19 +0000 (22:02 +0100)]
Register automatically the array loader on all the builtins
Also added reg* types to the known builtins. This way regtype[] is
loaded as a list of strings.
Daniele Varrazzo [Sun, 20 Dec 2020 18:23:20 +0000 (19:23 +0100)]
Better use of Cython public properties
Daniele Varrazzo [Mon, 21 Dec 2020 01:39:23 +0000 (02:39 +0100)]
Enable cython faster call convention
Daniele Varrazzo [Mon, 21 Dec 2020 02:58:24 +0000 (03:58 +0100)]
Release the gil around functions known to be slow
Profiling some time ago showed that these functions take relevant time.
Other paths will be reviewed.
https://www.varrazzo.com/blog/2020/05/19/a-trip-into-optimisation/
Daniele Varrazzo [Fri, 18 Dec 2020 20:08:05 +0000 (21:08 +0100)]
Added website to sponsors file
Daniele Varrazzo [Fri, 18 Dec 2020 13:55:46 +0000 (14:55 +0100)]
Added @postgrespro sponsor!
Thank you Oleg!
Daniele Varrazzo [Thu, 17 Dec 2020 16:29:48 +0000 (17:29 +0100)]
Added _oid C attribute to CDumper
Daniele Varrazzo [Thu, 17 Dec 2020 12:55:56 +0000 (13:55 +0100)]
Reduce re-allocations in objects quoting
Daniele Varrazzo [Thu, 17 Dec 2020 11:50:48 +0000 (12:50 +0100)]
Fixed broken previous commit
Daniele Varrazzo [Thu, 17 Dec 2020 04:55:56 +0000 (05:55 +0100)]
escape_string, escape_identifier use buffers too
Daniele Varrazzo [Thu, 17 Dec 2020 04:13:25 +0000 (05:13 +0100)]
Make wider use of Composite.as_bytes
Daniele Varrazzo [Thu, 17 Dec 2020 04:02:35 +0000 (05:02 +0100)]
Added buffer object to wrap libpq memory
Several code paths extended to deal with objects implementing the buffer
protocol instead of just bytes: this allows to perform less memory copy.
Added sql.Composable.as_bytes method to use in preference of as_string
(you may do without decoding altogether).
Daniele Varrazzo [Thu, 17 Dec 2020 01:29:09 +0000 (02:29 +0100)]
Added bytearray and memoryview dumpers
Also manage these objects when they rich the libp param passing.
Daniele Varrazzo [Wed, 16 Dec 2020 21:06:17 +0000 (22:06 +0100)]
Dropped use of a couple of constants in json
Daniele Varrazzo [Wed, 16 Dec 2020 21:05:02 +0000 (22:05 +0100)]
Added docs about string/binary adaptation
Daniele Varrazzo [Thu, 10 Dec 2020 12:41:59 +0000 (13:41 +0100)]
Sponsorship by @commandprompt - Thank you very much @jdatcmd
Daniele Varrazzo [Thu, 10 Dec 2020 12:19:22 +0000 (13:19 +0100)]
Added @mailupinc sponsor. Thank you!
Daniele Varrazzo [Thu, 10 Dec 2020 12:08:19 +0000 (13:08 +0100)]
Sponsorship by @phenopolis from @pontikos
Thank you very much, Niko!
Daniele Varrazzo [Thu, 10 Dec 2020 12:01:17 +0000 (13:01 +0100)]
Updated sponsorship by @gporcari @genropy
Grazie tantissime, Giovanni!
Daniele Varrazzo [Thu, 10 Dec 2020 11:04:46 +0000 (12:04 +0100)]
Backers file converted to yaml
It will be displayed at https://www.psycopg.org/sponsors/
Daniele Varrazzo [Thu, 10 Dec 2020 02:51:36 +0000 (03:51 +0100)]
Added several range tests and fixed a pasto error
Daniele Varrazzo [Thu, 10 Dec 2020 01:43:55 +0000 (02:43 +0100)]
Merge branch 'range-adaptation'
Daniele Varrazzo [Sun, 6 Dec 2020 02:50:50 +0000 (02:50 +0000)]
Added range type fetching and registration
Fixed quoting of [ ] chars for range types: unlike for composite they
need quoting.
Daniele Varrazzo [Sun, 6 Dec 2020 01:35:16 +0000 (01:35 +0000)]
Fetch/register composite made methods of a CompositeInfo class.