Hello, [ For my actual question, without the background, search for "QUESTION". ]
I encountered a situation where it began to matter that fetchall() was
pretty slow. It turns out that the bulk of the cost of doing a
fetchall() is due to:
(1) Primarily, the cost of comparing the type of each value against the
pre-defined pgdbType instances. This is expensive because it ends up
being a string comparison of the value type, with several lists of
strings (not necessarily in an optimal order).
(2) string->number conversions.
In my particlar test case selecting about 750 rows with about 10
columns, fetchall() takes on the order of 250 ms.
By performing the type comparison once for each query, caching
typecaster functions (one for each column), the same fetchall() takes
about 30-40 ms on average.
By performing the type check for every value, but by caching type
casters in a dictionary keyed on the value type, the query takes about
40-60 ms on average.
So it is clear that a very significant performance improvement can be
had with fairly simple changes (limited to Python code only), and I'd
like to come up with a patch for this (the current code is a hack and
needs to be tidied up for actual submission).
QUESTION:
So in order to decide whether to go the way of caching or go the way
of making the type comparison once, I need to know whether it is
actually possible/allowable for the type of a value to change on a
per-row basis. My knowledge of PostgreSQL when it comes to these types
of things is not extensive enough for me to know off hand; I would
have "supposed" that the type would be constant even in the presents
of custom types / type hierarchies, but the fact that the type of a
value is communicated on a per-value basis rather than as part of a
per-query result set header suggests to me that this is not the case.
Can someone confirm or deny that the type of a particular column can
indeed vary depending on the row?
--
/ Peter Schuller
PGP userID: 0xE9758B7D or 'Peter Schuller <[EMAIL PROTECTED]>'
Key retrieval: Send an E-Mail to [EMAIL PROTECTED]
E-Mail: [EMAIL PROTECTED] Web: http://www.scode.org
pgprRibirEA6h.pgp
Description: PGP signature
_______________________________________________ PyGreSQL mailing list [email protected] http://mailman.vex.net/mailman/listinfo/pygresql
