Re: [PATCH] Add missing type conversion functions for PL/Python

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>, David Steele <david(at)pgmasters(dot)net>, Haozhou Wang <hawang(at)pivotal(dot)io>, Anthony Bykov <a(dot)bykov(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)postgresql(dot)org, Paul Guo <pguo(at)pivotal(dot)io>, Hubert Zhang <hzhang(at)pivotal(dot)io>
Subject: Re: [PATCH] Add missing type conversion functions for PL/Python
Date: 2018-07-11 18:03:00
Message-ID: 2b1ed3ca-288f-3d60-2d2a-93332a9b2aa8@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26/03/18 19:07, Nikita Glukhov wrote:
> Attached fixed 3th version of the patch:

Thanks, I'm reviewing this now. Nice speedup!

There is no test coverage for some of the added code. You can get a code
coverage report with:

./configure --enable-coverage ...
make
make -C src/pl/plpython check
make coverage-html

That produces a code coverage report in coverage/index.html. Please look
at the coverage of the new functions, and add tests to
src/pl/plpython/sql/plpython_types.sql so that all the new code is covered.

In some places, where you've already checked the object type e.g. with
PyFloat_Check(), I think you could use the less safe variants, like
PyFloat_AS_DOUBLE() instead of PyFloat_AsDouble(). Since this patch is
all about performance, seems worth doing.

Some of the conversions seem a bit questionable. For example:

> /*
> * Convert a Python object to a PostgreSQL float8 datum directly.
> * If can not convert it directly, fallback to PLyObject_ToScalar
> * to convert it.
> */
> static Datum
> PLyObject_ToFloat8(PLyObToDatum *arg, PyObject *plrv,
> bool *isnull, bool inarray)
> {
> if (plrv == Py_None)
> {
> *isnull = true;
> return (Datum) 0;
> }
>
> if (PyFloat_Check(plrv) || PyInt_Check(plrv) || PyLong_Check(plrv))
> {
> *isnull = false;
> return Float8GetDatum((double)PyFloat_AsDouble(plrv));
> }
>
> return PLyObject_ToScalar(arg, plrv, isnull, inarray);
> }

The conversion from Python int to C double is performed by
PyFloat_AsDouble(). But there's no error checking. And wouldn't
PyLong_AsDouble() be more appropriate in that case, since we already
checked the python type?

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2018-07-11 18:04:17 Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors
Previous Message Alvaro Herrera 2018-07-11 17:49:06 Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors