On 12/28/16 3:14 AM, Craig Ringer wrote:
On 28 December 2016 at 12:32, Jim Nasby <jim.na...@bluetreble.com> wrote:
On 12/27/16 9:10 PM, Craig Ringer wrote:

On 28 December 2016 at 09:58, Jim Nasby <jim.na...@bluetreble.com> wrote:

I've looked at this some more, and ITSM that the only way to do this
without
some major surgery is to create a new type of Destination specifically
for
SPI that allows for the execution of an arbitrary C function for each
tuple
to be sent.


That sounds a lot more sensible than the prior proposals. Callback driven.


Are there other places this would be useful? I'm reluctant to write all of
this just to discover it doesn't help performance at all, but if it's useful
on it's own I can just submit it as a stand-alone patch.

I don't have a use for it personally. In BDR and pglogical anything
that does work with nontrivial numbers of tuples uses lower level
scans anyway.

I expect anything that uses the SPI to run arbitrary user queries
could have a use for something like this though. Any PL, for one.

Just a quick update on this: I've gotten this working well enough in plpython to do some performance testing. This patch does change python results from being a list of dicts to a dict of lists, but I suspect the vast majority of the speed improvement is from not creating a tuplestore.

The attached sample (from OS X /usr/bin/sample) is interesting. The highlight is:

!       3398 SPI_execute_callback  (in postgres) + 163  [0x110125793]
!         3394 _SPI_execute_plan  (in postgres) + 1262  [0x1101253fe]
!         : 2043 standard_ExecutorRun  (in postgres) + 288  [0x1100f9a40]
!         : | 1990 ExecProcNode  (in postgres) + 250  [0x1100fd62a]

The top line is the entry into SPI from plpython. The bottom line is generate_series into a tuplestore and then reading from that tuplestore. Almost all the time being spent in standard_ExecutorRun is in PLy_CSreceive, which is appending values to a set of python lists as it's getting tuples.

The other noteworthy item in the sample is this:

535 list_dealloc  (in Python) + 116,103,...  [0x11982b1b4,0x11982b1a7,...]

that's how long it's taking python to free the 3 lists (each with 9999999 python int objects).

In short (and at best*), this makes plpython just as fast at processing results as SELECT count(SELECT s, s, s FROM generate_series()).

The * on that is there's something odd going on where plpython starts out really fast at this, then gets 100% slower. I've reached out to some python folks about that. Even so, the overall results from a quick test on my laptop are (IMHO) impressive:

            Old Code        New Code    Improvement
Pure SQL    2 sec          2 sec
plpython    12.7-14 sec    4-10 sec     ~1.3-3x
plpython - SQL 10.7-12 sec 2-8 sec      ~1.3-6x

Pure SQL is how long an equivalent query takes to run with just SQL.
plpython - SQL is simply the raw python times minus the pure SQL time.

I suspect other PL languages that have fairly fast object alloc and dealloc would see a similar benefit.

BTW, the patch currently breaks on nested calls to plpython, but I don't think that should change the performance much.

The test function:
CREATE OR REPLACE FUNCTION test_series(
        iter int
) RETURNS int LANGUAGE plpythonu AS $body$
d = plpy.execute('SELECT s AS some_table_id, s AS some_field_name, s AS 
some_other_field_name FROM generate_series(1,{}) s'.format(iter) )
return len(d['some_table_id'])
$body$;
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 80fc4c4725..ace30d75f0 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -55,7 +55,8 @@ static void _SPI_prepare_oneshot_plan(const char *src, 
SPIPlanPtr plan);
 
 static int _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
                                  Snapshot snapshot, Snapshot 
crosscheck_snapshot,
-                                 bool read_only, bool fire_triggers, uint64 
tcount);
+                                 bool read_only, bool fire_triggers, uint64 
tcount,
+                                 DestReceiver *callback);
 
 static ParamListInfo _SPI_convert_params(int nargs, Oid *argtypes,
                                        Datum *Values, const char *Nulls);
@@ -320,7 +321,34 @@ SPI_execute(const char *src, bool read_only, long tcount)
 
        res = _SPI_execute_plan(&plan, NULL,
                                                        InvalidSnapshot, 
InvalidSnapshot,
-                                                       read_only, true, 
tcount);
+                                                       read_only, true, 
tcount, NULL);
+
+       _SPI_end_call(true);
+       return res;
+}
+int
+SPI_execute_callback(const char *src, bool read_only, long tcount,
+               DestReceiver *callback)
+{
+       _SPI_plan       plan;
+       int                     res;
+
+       if (src == NULL || tcount < 0)
+               return SPI_ERROR_ARGUMENT;
+
+       res = _SPI_begin_call(true);
+       if (res < 0)
+               return res;
+
+       memset(&plan, 0, sizeof(_SPI_plan));
+       plan.magic = _SPI_PLAN_MAGIC;
+       plan.cursor_options = 0;
+
+       _SPI_prepare_oneshot_plan(src, &plan);
+
+       res = _SPI_execute_plan(&plan, NULL,
+                                                       InvalidSnapshot, 
InvalidSnapshot,
+                                                       read_only, true, 
tcount, callback);
 
        _SPI_end_call(true);
        return res;
@@ -354,7 +382,34 @@ SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const 
char *Nulls,
                                                        
_SPI_convert_params(plan->nargs, plan->argtypes,
                                                                                
                Values, Nulls),
                                                        InvalidSnapshot, 
InvalidSnapshot,
-                                                       read_only, true, 
tcount);
+                                                       read_only, true, 
tcount, NULL);
+
+       _SPI_end_call(true);
+       return res;
+}
+
+/* Execute a previously prepared plan with a callback Destination */
+int
+SPI_execute_plan_callback(SPIPlanPtr plan, Datum *Values, const char *Nulls,
+                                bool read_only, long tcount, DestReceiver 
*callback)
+{
+       int                     res;
+
+       if (plan == NULL || plan->magic != _SPI_PLAN_MAGIC || tcount < 0)
+               return SPI_ERROR_ARGUMENT;
+
+       if (plan->nargs > 0 && Values == NULL)
+               return SPI_ERROR_PARAM;
+
+       res = _SPI_begin_call(true);
+       if (res < 0)
+               return res;
+
+       res = _SPI_execute_plan(plan,
+                                                       
_SPI_convert_params(plan->nargs, plan->argtypes,
+                                                                               
                Values, Nulls),
+                                                       InvalidSnapshot, 
InvalidSnapshot,
+                                                       read_only, true, 
tcount, callback);
 
        _SPI_end_call(true);
        return res;
@@ -383,7 +438,7 @@ SPI_execute_plan_with_paramlist(SPIPlanPtr plan, 
ParamListInfo params,
 
        res = _SPI_execute_plan(plan, params,
                                                        InvalidSnapshot, 
InvalidSnapshot,
-                                                       read_only, true, 
tcount);
+                                                       read_only, true, 
tcount, NULL);
 
        _SPI_end_call(true);
        return res;
@@ -424,7 +479,7 @@ SPI_execute_snapshot(SPIPlanPtr plan,
                                                        
_SPI_convert_params(plan->nargs, plan->argtypes,
                                                                                
                Values, Nulls),
                                                        snapshot, 
crosscheck_snapshot,
-                                                       read_only, 
fire_triggers, tcount);
+                                                       read_only, 
fire_triggers, tcount, NULL);
 
        _SPI_end_call(true);
        return res;
@@ -471,7 +526,7 @@ SPI_execute_with_args(const char *src,
 
        res = _SPI_execute_plan(&plan, paramLI,
                                                        InvalidSnapshot, 
InvalidSnapshot,
-                                                       read_only, true, 
tcount);
+                                                       read_only, true, 
tcount, NULL);
 
        _SPI_end_call(true);
        return res;
@@ -1892,7 +1947,8 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr 
plan)
 static int
 _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
                                  Snapshot snapshot, Snapshot 
crosscheck_snapshot,
-                                 bool read_only, bool fire_triggers, uint64 
tcount)
+                                 bool read_only, bool fire_triggers, uint64 
tcount,
+                                 DestReceiver *callback)
 {
        int                     my_res = 0;
        uint64          my_processed = 0;
@@ -1903,6 +1959,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
        ErrorContextCallback spierrcontext;
        CachedPlan *cplan = NULL;
        ListCell   *lc1;
+       DestReceiver *dest = callback;
 
        /*
         * Setup error traceback support for ereport()
@@ -2020,7 +2077,6 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
                {
                        Node       *stmt = (Node *) lfirst(lc2);
                        bool            canSetTag;
-                       DestReceiver *dest;
 
                        _SPI_current->processed = 0;
                        _SPI_current->lastoid = InvalidOid;
@@ -2072,7 +2128,8 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
                                UpdateActiveSnapshotCommandId();
                        }
 
-                       dest = CreateDestReceiver(canSetTag ? DestSPI : 
DestNone);
+                       if (!callback)
+                               dest = CreateDestReceiver(canSetTag ? DestSPI : 
DestNone);
 
                        if (IsA(stmt, PlannedStmt) &&
                                ((PlannedStmt *) stmt)->utilityStmt == NULL)
@@ -2098,6 +2155,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
                        {
                                char            
completionTag[COMPLETION_TAG_BUFSIZE];
 
+                               // XXX throw error if callback is set
                                ProcessUtility(stmt,
                                                           
plansource->query_string,
                                                           
PROCESS_UTILITY_QUERY,
diff --git a/src/backend/tcop/dest.c b/src/backend/tcop/dest.c
index 60a92801f1..212cfbd101 100644
--- a/src/backend/tcop/dest.c
+++ b/src/backend/tcop/dest.c
@@ -81,6 +81,11 @@ static DestReceiver spi_printtupDR = {
        DestSPI
 };
 
+static DestReceiver spi_callbackDR = {
+       donothingReceive, donothingStartup, donothingCleanup, donothingCleanup,
+       DestSPICallback
+};
+
 /* Globally available receiver for DestNone */
 DestReceiver *None_Receiver = &donothingDR;
 
@@ -117,6 +122,9 @@ CreateDestReceiver(CommandDest dest)
                case DestSPI:
                        return &spi_printtupDR;
 
+               case DestSPICallback:
+                       return &spi_callbackDR;
+
                case DestTuplestore:
                        return CreateTuplestoreDestReceiver();
 
@@ -162,6 +170,7 @@ EndCommand(const char *commandTag, CommandDest dest)
                case DestNone:
                case DestDebug:
                case DestSPI:
+               case DestSPICallback:
                case DestTuplestore:
                case DestIntoRel:
                case DestCopyOut:
@@ -205,6 +214,7 @@ NullCommand(CommandDest dest)
                case DestNone:
                case DestDebug:
                case DestSPI:
+               case DestSPICallback:
                case DestTuplestore:
                case DestIntoRel:
                case DestCopyOut:
@@ -250,6 +260,7 @@ ReadyForQuery(CommandDest dest)
                case DestNone:
                case DestDebug:
                case DestSPI:
+               case DestSPICallback:
                case DestTuplestore:
                case DestIntoRel:
                case DestCopyOut:
diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h
index 76ba394a2b..15187c47e3 100644
--- a/src/include/executor/spi.h
+++ b/src/include/executor/spi.h
@@ -74,11 +74,15 @@ extern PGDLLIMPORT int SPI_result;
 extern int     SPI_connect(void);
 extern int     SPI_finish(void);
 extern int     SPI_execute(const char *src, bool read_only, long tcount);
+extern int     SPI_execute_callback(const char *src, bool read_only, long 
tcount,
+                                                                       
DestReceiver *callback);
 extern int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
                                 bool read_only, long tcount);
 extern int SPI_execute_plan_with_paramlist(SPIPlanPtr plan,
                                                                ParamListInfo 
params,
                                                                bool read_only, 
long tcount);
+extern int SPI_execute_plan_callback(SPIPlanPtr plan, Datum *Values, const 
char *Nulls,
+                                bool read_only, long tcount, DestReceiver 
*callback);
 extern int     SPI_exec(const char *src, long tcount);
 extern int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls,
                  long tcount);
diff --git a/src/include/tcop/dest.h b/src/include/tcop/dest.h
index dd80433f74..5389f496a2 100644
--- a/src/include/tcop/dest.h
+++ b/src/include/tcop/dest.h
@@ -90,6 +90,7 @@ typedef enum
        DestRemote,                                     /* results sent to 
frontend process */
        DestRemoteExecute,                      /* sent to frontend, in Execute 
command */
        DestSPI,                                        /* results sent to SPI 
manager */
+       DestSPICallback,                        /* results sent to 
user-specified callback function */
        DestTuplestore,                         /* results sent to Tuplestore */
        DestIntoRel,                            /* results sent to relation 
(SELECT INTO) */
        DestCopyOut,                            /* results sent to COPY TO code 
*/
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 860b804e54..07501f18f2 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -403,6 +403,19 @@ PLy_current_execution_context(void)
        return PLy_execution_contexts;
 }
 
+PLyExecutionContext *
+PLy_switch_execution_context(PLyExecutionContext *new)
+{
+       PLyExecutionContext *last = PLy_execution_contexts;
+
+       if (PLy_execution_contexts == NULL)
+               elog(ERROR, "no Python function is currently executing");
+
+       PLy_execution_contexts = new;
+
+       return last;
+}
+
 MemoryContext
 PLy_get_scratch_context(PLyExecutionContext *context)
 {
diff --git a/src/pl/plpython/plpy_main.h b/src/pl/plpython/plpy_main.h
index 10426c4323..7cbe0a8d35 100644
--- a/src/pl/plpython/plpy_main.h
+++ b/src/pl/plpython/plpy_main.h
@@ -25,6 +25,9 @@ typedef struct PLyExecutionContext
 /* Get the current execution context */
 extern PLyExecutionContext *PLy_current_execution_context(void);
 
+/* Get switch execution contexts */
+extern PLyExecutionContext *PLy_switch_execution_context(PLyExecutionContext 
*new);
+
 /* Get the scratch memory context for specified execution context */
 extern MemoryContext PLy_get_scratch_context(PLyExecutionContext *context);
 
diff --git a/src/pl/plpython/plpy_spi.c b/src/pl/plpython/plpy_spi.c
index 07ab6a087e..ab303367d3 100644
--- a/src/pl/plpython/plpy_spi.c
+++ b/src/pl/plpython/plpy_spi.c
@@ -28,8 +28,27 @@
 #include "plpy_procedure.h"
 #include "plpy_resultobject.h"
 
+typedef struct
+{
+       DestReceiver pub;
+       PLyExecutionContext *exec_ctx;
+       MemoryContext mctx;
+       TupleDesc       desc;
+       PLyTypeInfo *args;
+
+       /* Dictionary of Lists */
+       PyObject        *dict;
+       PyObject        **lists;
+} CallbackState;
+
+
+
+void PLy_CSStartup(DestReceiver *self, int operation, TupleDesc typeinfo);
+void PLy_CSDestroy(DestReceiver *self);
+static bool PLy_CSreceive(TupleTableSlot *slot, DestReceiver *self);
 
 static PyObject *PLy_spi_execute_query(char *query, long limit);
+static PyObject *PLy_spi_execute_query2(char *query, long limit);
 static PyObject *PLy_spi_execute_plan(PyObject *ob, PyObject *list, long 
limit);
 static PyObject *PLy_spi_execute_fetch_result(SPITupleTable *tuptable,
                                                         uint64 rows, int 
status);
@@ -341,8 +360,159 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long 
limit)
        return ret;
 }
 
+void
+PLy_CSStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
+{
+       PLyExecutionContext *old_exec_ctx;
+       CallbackState *myState = (CallbackState *) self;
+       PLyTypeInfo *args;
+       
+       MemoryContext mctx, old_mctx;
+       PyObject *dict;
+       PyObject **lists;
+       int                     i;
+
+       /*
+        * We may be in a different execution context when we're called, so 
switch
+        * back to our original one.
+        */
+       mctx = myState->mctx;
+       old_exec_ctx = PLy_switch_execution_context(myState->exec_ctx);
+       old_mctx = MemoryContextSwitchTo(mctx);
+       
+       /* Store this as a sanity check */
+       myState->desc = typeinfo;
+
+       /* Setup type conversion info */
+       myState->args = args = palloc0(sizeof(PLyTypeInfo));
+       PLy_typeinfo_init(args, mctx);
+       PLy_input_tuple_funcs(args, typeinfo);
+
+       /*
+        * We never palloc python objects, but this is an array of object 
pointers,
+        * so it's OK.
+        */
+       myState->lists = lists = palloc0(args->in.r.natts * sizeof(PyObject *));
+
+       myState->dict = dict = PyDict_New();
+       if (dict == NULL)
+               PLy_elog(ERROR, "could not create new dictionary");
+
+
+       for (i = 0; i < args->in.r.natts; i++)
+       {
+               char       *key;
+               PyObject   *value;
+
+               if (typeinfo->attrs[i]->attisdropped)
+                       continue;
+
+               /* NOTE: If size is > 0 then the list must get initialized! */
+               value = PyList_New(0);
+               if (value == NULL)
+                       PLy_elog(ERROR, "could not create new list");
+
+               key = NameStr(typeinfo->attrs[i]->attname);
+               PyDict_SetItemString(dict, key, value);
+               Py_DECREF(value);
+
+               /* We want fast access to the lists, so we store them in our 
array of pointers */
+               lists[i] = value;
+       }
+
+       MemoryContextSwitchTo(old_mctx);
+       PLy_switch_execution_context(old_exec_ctx);
+}
+
+void
+PLy_CSDestroy(DestReceiver *self)
+{
+       CallbackState *myState = (CallbackState *) self;
+       
+       MemoryContextDelete(myState->mctx);
+}
+
+static bool
+PLy_CSreceive(TupleTableSlot *slot, DestReceiver *self)
+{
+       TupleDesc               desc = slot->tts_tupleDescriptor;
+       CallbackState   *myState = (CallbackState *) self;
+       PLyTypeInfo     *args = myState->args;
+       PLyExecutionContext *old_exec_ctx = 
PLy_switch_execution_context(myState->exec_ctx);
+       MemoryContext   scratch_context = 
PLy_get_scratch_context(myState->exec_ctx);
+       MemoryContext   oldcontext = CurrentMemoryContext;
+       int                     i, rv;
+
+       /* Verify saved state matches incoming slot */
+       Assert(myState->desc == desc);
+       Assert(args->in.r.natts == desc->natts);
+
+       /* Make sure the tuple is fully deconstructed */
+       slot_getallattrs(slot);
+
+       MemoryContextSwitchTo(scratch_context);
+
+
+       /*
+        * Do the work in the scratch context to avoid leaking memory from the
+        * datatype output function calls.
+        */
+       for (i = 0; i < desc->natts; i++)
+       {
+               PyObject                * volatile value = NULL;
+               PLyDatumToOb    * volatile atts = &args->in.r.atts[i];
+
+               if (desc->attrs[i]->attisdropped)
+                       continue;
+
+               if (myState->lists[i] == NULL)
+                       ereport(ERROR,
+                                       (errmsg("missing list for attribute 
%d", i)));
+               /* XXX If the function can't be null, ditch that check */
+               if (slot->tts_isnull[i] || atts->func == NULL)
+               {
+                       Py_INCREF(Py_None);
+                       value = Py_None;
+               }
+               else
+               {
+                       PG_TRY();
+                       {
+                               value = (atts->func) (atts, 
slot->tts_values[i]);
+                       }
+                       PG_CATCH();
+                       {
+                               Py_XDECREF(value);
+                               MemoryContextSwitchTo(oldcontext);
+                               PLy_switch_execution_context(old_exec_ctx);
+                               PG_RE_THROW();
+                       }
+                       PG_END_TRY();
+               }
+
+               /*
+                * If we tried to do this in the PG_CATCH we'd have to mark 
value
+                * as volatile, but that won't work with PyList_Append, so just
+                * test the error code after doing Py_DECREF().
+                */
+               rv = PyList_Append(myState->lists[i], value);
+               Py_DECREF(value);
+               
+               if (rv != 0)
+                       ereport(ERROR,
+                                       (errmsg("unable to append value to 
list")));
+       }
+       MemoryContextSwitchTo(oldcontext);
+       /* Should we just do this once, for the whole tuple?? */
+       MemoryContextReset(scratch_context);
+       PLy_switch_execution_context(old_exec_ctx);
+
+       /* If we get here then we were successful */
+       return true;
+}
+
 static PyObject *
-PLy_spi_execute_query(char *query, long limit)
+PLy_spi_execute_query2(char *query, long limit)
 {
        int                     rv;
        volatile MemoryContext oldcontext;
@@ -384,6 +554,75 @@ PLy_spi_execute_query(char *query, long limit)
 }
 
 static PyObject *
+PLy_spi_execute_query(char *query, long limit)
+{
+       PLyExecutionContext *exec_ctx = PLy_current_execution_context();
+       int                     rv;
+       volatile MemoryContext oldcontext, cb_ctx;
+       volatile ResourceOwner oldowner;
+       PyObject   *ret = NULL;
+       CallbackState   callback;
+
+       oldowner = CurrentResourceOwner;
+
+       /*
+        * Use a new context to make cleanup easier. Allocate it in the current
+        * context so we don't have to worry about cleaning it up if there's an
+        * error.
+        */
+       cb_ctx = AllocSetContextCreate(CurrentMemoryContext,
+                                                               "PL/Python 
callback context",
+                                                               
ALLOCSET_DEFAULT_SIZES);
+
+       oldcontext = MemoryContextSwitchTo(cb_ctx);
+       //callback = palloc0(sizeof(CallbackState));
+       callback.mctx = cb_ctx;
+       memcpy(&(callback.pub), CreateDestReceiver(DestSPICallback), 
sizeof(DestReceiver));
+       callback.pub.receiveSlot = PLy_CSreceive;
+       callback.pub.rStartup = PLy_CSStartup;
+       //callback.pub.rDestroy = PLy_CSDestroy;
+       callback.exec_ctx = exec_ctx;
+
+       PLy_spi_subtransaction_begin(oldcontext, oldowner);
+
+       PG_TRY();
+       {
+
+               pg_verifymbstr(query, strlen(query), false);
+               rv = SPI_execute_callback(query, 
exec_ctx->curr_proc->fn_readonly, limit,
+                               (DestReceiver *) &callback);
+               /*
+                * callback.dict gets set in PLy_CSStartup, which happens during
+                * executor startup. It's not valid before then.
+                */
+               ret = callback.dict;
+
+               PLy_spi_subtransaction_commit(oldcontext, oldowner);
+       }
+       PG_CATCH();
+       {
+               PLy_spi_subtransaction_abort(oldcontext, oldowner);
+               return NULL;
+       }
+       PG_END_TRY();
+
+       if (rv < 0)
+       {
+               Py_XDECREF(ret);
+               PLy_exception_set(PLy_exc_spi_error,
+                                                 "SPI_execute failed: %s",
+                                                 SPI_result_code_string(rv));
+               return NULL;
+       }
+
+       /* Free the callback context. */
+       MemoryContextSwitchTo(oldcontext);
+       MemoryContextDelete(cb_ctx);
+
+       return ret;
+}
+
+static PyObject *
 PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
 {
        PLyResultObject *result;
Analysis of sampling postgres (pid 37932) every 1 millisecond
Process:         postgres [37932]
Path:            /Users/decibel/pgsql/HEAD/i/bin/postgres
Load Address:    0x10ff94000
Identifier:      postgres
Version:         0
Code Type:       X86-64
Parent Process:  postgres [37852]

Date/Time:       2017-01-05 21:26:08.742 -0600
Launch Time:     2017-01-05 21:25:15.289 -0600
OS Version:      Mac OS X 10.11.6 (15G1212)
Report Version:  7
Analysis Tool:   /usr/bin/sample
----

Call graph:
    8991 Thread_5935162   DispatchQueue_1: com.apple.main-thread  (serial)
      8991 start  (in libdyld.dylib) + 1  [0x7fff8c3bb5ad]
        8991 main  (in postgres) + 1562  [0x1101363ca]
          8991 PostmasterMain  (in postgres) + 7443  [0x1101b1093]
            4996 PostgresMain  (in postgres) + 1349  [0x11021b7e5]
            + 4996 pq_getbyte  (in postgres) + 36  [0x110133924]
            +   4996 pq_recvbuf  (in postgres) + 172  [0x1101339fc]
            +     4996 secure_read  (in postgres) + 144  [0x11012c130]
            +       4996 WaitEventSetWait  (in postgres) + 199  [0x1101f98d7]
            +         4996 poll  (in libsystem_kernel.dylib) + 10  
[0x7fff8df942a2]
            3995 PostgresMain  (in postgres) + 8745  [0x11021d4c9]
              3995 PortalRun  (in postgres) + 500  [0x11021f2f4]
                3995 PortalRunSelect  (in postgres) + 239  [0x11021f6ef]
                  3995 standard_ExecutorRun  (in postgres) + 288  [0x1100f9a40]
                    3995 ExecProcNode  (in postgres) + 94  [0x1100fd58e]
                      3995 ExecResult  (in postgres) + 179  [0x11011ab23]
                        3995 ExecProject  (in postgres) + 590  [0x110103e0e]
                          3995 ExecMakeFunctionResultNoSets  (in postgres) + 
209  [0x110104971]
                            3995 plpython_call_handler  (in plpython2.so) + 277 
 [0x1108c0ce5]
                              3995 PLy_exec_function  (in plpython2.so) + 915  
[0x1108beb13]
                                3995 PLy_procedure_call  (in plpython2.so) + 
143  [0x1108bf4df]
                                  3995 PyEval_EvalCode  (in Python) + 54  
[0x11989b876]
                                    3995 PyEval_EvalCodeEx  (in Python) + 2100  
[0x11989c0b4]
                                      3995 PyEval_EvalFrameEx  (in Python) + 
29092  [0x1198a35e4]
                                        3398 fast_function  (in Python) + 338  
[0x1198a83d2]
                                        ! 3398 PyEval_EvalFrameEx  (in Python) 
+ 30112  [0x1198a39e0]
                                        !   3398 PLy_spi_execute  (in 
plpython2.so) + 70  [0x1108c3eb6]
                                        !     3398 PLy_spi_execute_query  (in 
plpython2.so) + 428  [0x1108c40dc]
                                        !       3398 SPI_execute_callback  (in 
postgres) + 163  [0x110125793]
                                        !         3394 _SPI_execute_plan  (in 
postgres) + 1262  [0x1101253fe]
                                        !         : 2043 standard_ExecutorRun  
(in postgres) + 288  [0x1100f9a40]
                                        !         : | 1990 ExecProcNode  (in 
postgres) + 250  [0x1100fd62a]
                                        !         : | + 1581 ExecScan  (in 
postgres) + 186  [0x110104aca]
                                        !         : | + ! 957 FunctionNext  (in 
postgres) + 99  [0x110119d13]
                                        !         : | + ! : 789 
ExecMakeTableFunctionResult  (in postgres) + 799  [0x1100fe38f]
                                        !         : | + ! : | 446 
tuplestore_putvalues  (in postgres) + 71  [0x11035ac77]
                                        !         : | + ! : | + 176 
writetup_heap  (in postgres) + 69  [0x11035a045]
                                        !         : | + ! : | + ! 82 
BufFileWrite  (in postgres) + 71  [0x1101f4057]
                                        !         : | + ! : | + ! : 82 
BufFileDumpBuffer  (in postgres) + 341  [0x1101f4255]
                                        !         : | + ! : | + ! :   80 
FileWrite  (in postgres) + 161  [0x1101f2221]
                                        !         : | + ! : | + ! :   | 80 
write  (in libsystem_kernel.dylib) + 10  [0x7fff8df9491a]
                                        !         : | + ! : | + ! :   1 
FileWrite  (in postgres) + 28  [0x1101f219c]
                                        !         : | + ! : | + ! :   | 1 
FileAccess  (in postgres) + 303  [0x1101f20df]
                                        !         : | + ! : | + ! :   1 
FileWrite  (in postgres) + 239  [0x1101f226f]
                                        !         : | + ! : | + ! 60 
BufFileWrite  (in postgres) + 6,159,...  [0x1101f4016,0x1101f40af,...]
                                        !         : | + ! : | + ! 29 
BufFileWrite  (in postgres) + 170  [0x1101f40ba]
                                        !         : | + ! : | + ! : 29 
_platform_memmove$VARIANT$Haswell  (in libsystem_platform.dylib) + 171,7,...  
[0x7fff9aa29fcb,0x7fff9aa29f27,...]
                                        !         : | + ! : | + ! 5 
DYLD-STUB$$memcpy  (in postgres) + 0  [0x11036f85e]
                                        !         : | + ! : | + 116 
writetup_heap  (in postgres) + 47  [0x11035a02f]
                                        !         : | + ! : | + ! 58 
BufFileWrite  (in postgres) + 190,141,...  [0x1101f40ce,0x1101f409d,...]
                                        !         : | + ! : | + ! 34 
BufFileWrite  (in postgres) + 71  [0x1101f4057]
                                        !         : | + ! : | + ! : 34 
BufFileDumpBuffer  (in postgres) + 341  [0x1101f4255]
                                        !         : | + ! : | + ! :   34 
FileWrite  (in postgres) + 161  [0x1101f2221]
                                        !         : | + ! : | + ! :     34 
write  (in libsystem_kernel.dylib) + 10  [0x7fff8df9491a]
                                        !         : | + ! : | + ! 24 
BufFileWrite  (in postgres) + 170  [0x1101f40ba]
                                        !         : | + ! : | + !   24 
_platform_memmove$VARIANT$Haswell  (in libsystem_platform.dylib) + 190,151,...  
[0x7fff9aa29fde,0x7fff9aa29fb7,...]
                                        !         : | + ! : | + 40 
writetup_heap  (in postgres) + 124  [0x11035a07c]
                                        !         : | + ! : | + ! 26 
AllocSetFree  (in postgres) + 228,139,...  [0x110348e74,0x110348e1b,...]
                                        !         : | + ! : | + ! 7 
heap_free_minimal_tuple  (in postgres) + 0,4,...  [0x10ff9d050,0x10ff9d054,...]
                                        !         : | + ! : | + ! 7 pfree  (in 
postgres) + 1,11,...  [0x11034e201,0x11034e20b,...]
                                        !         : | + ! : | + 38 
writetup_heap  (in postgres) + 112  [0x11035a070]
                                        !         : | + ! : | + ! 32 
GetMemoryChunkSpace  (in postgres) + 19,15,...  [0x11034e253,0x11034e24f,...]
                                        !         : | + ! : | + ! 6 
AllocSetGetChunkSpace  (in postgres) + 8,0  [0x1103490c8,0x1103490c0]
                                        !         : | + ! : | + 33 
writetup_heap  (in postgres) + 116,9,...  [0x11035a074,0x11035a009,...]
                                        !         : | + ! : | + 32 
tuplestore_puttuple_common  (in postgres) + 432,29,...  
[0x11035a990,0x11035a7fd,...]
                                        !         : | + ! : | + 7 pfree  (in 
postgres) + 23  [0x11034e217]
                                        !         : | + ! : | + 2 
heap_free_minimal_tuple  (in postgres) + 5  [0x10ff9d055]
                                        !         : | + ! : | + 1 
tuplestore_puttuple_common  (in postgres) + 720  [0x11035aab0]
                                        !         : | + ! : | + ! 1 
BufFileCreateTemp  (in postgres) + 18  [0x1101f3d82]
                                        !         : | + ! : | + !   1 
OpenTemporaryFile  (in postgres) + 120  [0x1101f1aa8]
                                        !         : | + ! : | + !     1 
OpenTemporaryFileInTablespace  (in postgres) + 264  [0x1101f1c68]
                                        !         : | + ! : | + !       1 
PathNameOpenFile  (in postgres) + 457  [0x1101f18d9]
                                        !         : | + ! : | + !         1 
BasicOpenFile  (in postgres) + 63  [0x1101f165f]
                                        !         : | + ! : | + !           1 
__open  (in libsystem_kernel.dylib) + 10  [0x7fff8df92c02]
                                        !         : | + ! : | + 1 
tuplestore_puttuple_common  (in postgres) + 786  [0x11035aaf2]
                                        !         : | + ! : | +   1 
writetup_heap  (in postgres) + 119  [0x11035a077]
                                        !         : | + ! : | 294 
tuplestore_putvalues  (in postgres) + 45  [0x11035ac5d]
                                        !         : | + ! : | + 132 
heap_form_minimal_tuple  (in postgres) + 159  [0x10ff9cf8f]
                                        !         : | + ! : | + ! 58 palloc0  
(in postgres) + 49  [0x11034eb71]
                                        !         : | + ! : | + ! : 58 
AllocSetAlloc  (in postgres) + 0,219,...  [0x110348ac0,0x110348b9b,...]
                                        !         : | + ! : | + ! 37 palloc0  
(in postgres) + 33,133,...  [0x11034eb61,0x11034ebc5,...]
                                        !         : | + ! : | + ! 36 palloc0  
(in postgres) + 125  [0x11034ebbd]
                                        !         : | + ! : | + ! : 36 
_platform_bzero$VARIANT$Haswell  (in libsystem_platform.dylib) + 115,131,...  
[0x7fff9aa2ac93,0x7fff9aa2aca3,...]
                                        !         : | + ! : | + ! 1 
DYLD-STUB$$__bzero  (in postgres) + 0  [0x11036f582]
                                        !         : | + ! : | + 61 
heap_form_minimal_tuple  (in postgres) + 245  [0x10ff9cfe5]
                                        !         : | + ! : | + ! 61 
heap_fill_tuple  (in postgres) + 4,448,...  [0x10ff9b164,0x10ff9b320,...]
                                        !         : | + ! : | + 54 
heap_form_minimal_tuple  (in postgres) + 228,0,...  
[0x10ff9cfd4,0x10ff9cef0,...]
                                        !         : | + ! : | + 47 
heap_form_minimal_tuple  (in postgres) + 145  [0x10ff9cf81]
                                        !         : | + ! : | +   47 
heap_compute_data_size  (in postgres) + 26,8,...  [0x10ff9afca,0x10ff9afb8,...]
                                        !         : | + ! : | 28 
tuplestore_putvalues  (in postgres) + 60,18,...  [0x11035ac6c,0x11035ac42,...]
                                        !         : | + ! : | 21 
tuplestore_putvalues  (in postgres) + 56  [0x11035ac68]
                                        !         : | + ! : |   16 
GetMemoryChunkSpace  (in postgres) + 19,15,...  [0x11034e253,0x11034e24f,...]
                                        !         : | + ! : |   5 
AllocSetGetChunkSpace  (in postgres) + 0,4  [0x1103490c0,0x1103490c4]
                                        !         : | + ! : 74 
ExecMakeTableFunctionResult  (in postgres) + 476  [0x1100fe24c]
                                        !         : | + ! : | 60 
generate_series_step_int4  (in postgres) + 195,144,...  
[0x110277a33,0x110277a00,...]
                                        !         : | + ! : | 9 
generate_series_step_int4  (in postgres) + 135  [0x1102779f7]
                                        !         : | + ! : | + 9 
per_MultiFuncCall  (in postgres) + 13,34,...  [0x11032c68d,0x11032c6a2,...]
                                        !         : | + ! : | 5 
generate_series_int4  (in postgres) + 0  [0x110277960]
                                        !         : | + ! : 32 
ExecMakeTableFunctionResult  (in postgres) + 504,958,...  
[0x1100fe268,0x1100fe42e,...]
                                        !         : | + ! : 25 
ExecMakeTableFunctionResult  (in postgres) + 450  [0x1100fe232]
                                        !         : | + ! : | 25 
pgstat_init_function_usage  (in postgres) + 4,319,...  
[0x1101ac024,0x1101ac15f,...]
                                        !         : | + ! : 20 
ExecMakeTableFunctionResult  (in postgres) + 504  [0x1100fe268]
                                        !         : | + ! : | 20 
pgstat_end_function_usage  (in postgres) + 0,15,...  
[0x1101ac190,0x1101ac19f,...]
                                        !         : | + ! : 15 
ExecMakeTableFunctionResult  (in postgres) + 384  [0x1100fe1f0]
                                        !         : | + ! : | 15 
MemoryContextReset  (in postgres) + 5,85,...  [0x11034df95,0x11034dfe5,...]
                                        !         : | + ! : 2 
generate_series_int4  (in postgres) + 5  [0x110277965]
                                        !         : | + ! 582 FunctionNext  (in 
postgres) + 144  [0x110119d40]
                                        !         : | + ! : 469 
tuplestore_gettupleslot  (in postgres) + 25  [0x11035aca9]
                                        !         : | + ! : | 165 
tuplestore_gettuple  (in postgres) + 272  [0x11035ae00]
                                        !         : | + ! : | + 120 getlen  (in 
postgres) + 26  [0x11035b77a]
                                        !         : | + ! : | + ! 60 
BufFileRead  (in postgres) + 0,13,...  [0x1101f3e80,0x1101f3e8d,...]
                                        !         : | + ! : | + ! 36 
BufFileRead  (in postgres) + 348  [0x1101f3fdc]
                                        !         : | + ! : | + ! : 36 
_platform_memmove$VARIANT$Haswell  (in libsystem_platform.dylib) + 0,186,...  
[0x7fff9aa29f20,0x7fff9aa29fda,...]
                                        !         : | + ! : | + ! 23 
BufFileRead  (in postgres) + 259  [0x1101f3f83]
                                        !         : | + ! : | + ! : 23 FileRead 
 (in postgres) + 70  [0x1101f2136]
                                        !         : | + ! : | + ! :   23 read  
(in libsystem_kernel.dylib) + 10  [0x7fff8df94362]
                                        !         : | + ! : | + ! 1 
DYLD-STUB$$memcpy  (in postgres) + 0  [0x11036f85e]
                                        !         : | + ! : | + 45 getlen  (in 
postgres) + 35,0,...  [0x11035b783,0x11035b760,...]
                                        !         : | + ! : | 127 readtup_heap  
(in postgres) + 74  [0x11035a14a]
                                        !         : | + ! : | + 58 BufFileRead  
(in postgres) + 259  [0x1101f3f83]
                                        !         : | + ! : | + ! 58 FileRead  
(in postgres) + 70  [0x1101f2136]
                                        !         : | + ! : | + !   58 read  
(in libsystem_kernel.dylib) + 10  [0x7fff8df94362]
                                        !         : | + ! : | + 51 BufFileRead  
(in postgres) + 325,81,...  [0x1101f3fc5,0x1101f3ed1,...]
                                        !         : | + ! : | + 17 BufFileRead  
(in postgres) + 348  [0x1101f3fdc]
                                        !         : | + ! : | + ! 17 
_platform_memmove$VARIANT$Haswell  (in libsystem_platform.dylib) + 0,71,...  
[0x7fff9aa29f20,0x7fff9aa29f67,...]
                                        !         : | + ! : | + 1 
DYLD-STUB$$memcpy  (in postgres) + 0  [0x11036f85e]
                                        !         : | + ! : | 90 readtup_heap  
(in postgres) + 37  [0x11035a125]
                                        !         : | + ! : | + 67 palloc  (in 
postgres) + 49  [0x11034ea91]
                                        !         : | + ! : | + ! 67 
AllocSetAlloc  (in postgres) + 211,219,...  [0x110348b93,0x110348b9b,...]
                                        !         : | + ! : | + 23 palloc  (in 
postgres) + 33,49,...  [0x11034ea81,0x11034ea91,...]
                                        !         : | + ! : | 37 readtup_heap  
(in postgres) + 6,126,...  [0x11035a106,0x11035a17e,...]
                                        !         : | + ! : | 28 
tuplestore_gettuple  (in postgres) + 0,13,...  [0x11035acf0,0x11035acfd,...]
                                        !         : | + ! : | 22 readtup_heap  
(in postgres) + 52  [0x11035a134]
                                        !         : | + ! : |   18 
GetMemoryChunkSpace  (in postgres) + 19,0,...  [0x11034e253,0x11034e240,...]
                                        !         : | + ! : |   4 
AllocSetGetChunkSpace  (in postgres) + 1,0,...  [0x1103490c1,0x1103490c0,...]
                                        !         : | + ! : 90 
tuplestore_gettupleslot  (in postgres) + 69  [0x11035acd5]
                                        !         : | + ! : | 49 
ExecStoreMinimalTuple  (in postgres) + 49  [0x110105301]
                                        !         : | + ! : | + 31 AllocSetFree 
 (in postgres) + 228,236,...  [0x110348e74,0x110348e7c,...]
                                        !         : | + ! : | + 11 pfree  (in 
postgres) + 19,4,...  [0x11034e213,0x11034e204,...]
                                        !         : | + ! : | + 7 
heap_free_minimal_tuple  (in postgres) + 0  [0x10ff9d050]
                                        !         : | + ! : | 39 
ExecStoreMinimalTuple  (in postgres) + 61,8,...  [0x11010530d,0x1101052d8,...]
                                        !         : | + ! : | 2 
heap_free_minimal_tuple  (in postgres) + 5  [0x10ff9d055]
                                        !         : | + ! : 23 
tuplestore_gettupleslot  (in postgres) + 11,61,...  
[0x11035ac9b,0x11035accd,...]
                                        !         : | + ! 22 FunctionNext  (in 
postgres) + 714,706,...  [0x110119f7a,0x110119f72,...]
                                        !         : | + ! 20 ExecScanFetch  (in 
postgres) + 0,10,...  [0x110104b80,0x110104b8a,...]
                                        !         : | + 315 ExecScan  (in 
postgres) + 244  [0x110104b04]
                                        !         : | + ! 148 ExecProject  (in 
postgres) + 192,188,...  [0x110103c80,0x110103c7c,...]
                                        !         : | + ! 108 ExecProject  (in 
postgres) + 117  [0x110103c35]
                                        !         : | + ! : 72 
slot_getsomeattrs  (in postgres) + 99  [0x10ff9cce3]
                                        !         : | + ! : | 72 
slot_deform_tuple  (in postgres) + 771,131,...  [0x10ff9cb83,0x10ff9c903,...]
                                        !         : | + ! : 36 
slot_getsomeattrs  (in postgres) + 91,36,...  [0x10ff9ccdb,0x10ff9cca4,...]
                                        !         : | + ! 46 ExecProject  (in 
postgres) + 50  [0x110103bf2]
                                        !         : | + ! : 46 ExecClearTuple  
(in postgres) + 13,47,...  [0x110104fdd,0x110104fff,...]
                                        !         : | + ! 13 
ExecStoreVirtualTuple  (in postgres) + 12,21,...  [0x11010536c,0x110105375,...]
                                        !         : | + 67 ExecScan  (in 
postgres) + 194,12,...  [0x110104ad2,0x110104a1c,...]
                                        !         : | + 20 ExecScan  (in 
postgres) + 126  [0x110104a8e]
                                        !         : | + ! 20 MemoryContextReset 
 (in postgres) + 5,89,...  [0x11034df95,0x11034dfe9,...]
                                        !         : | + 5 ExecFunctionScan  (in 
postgres) + 0,4,...  [0x110119c90,0x110119c94,...]
                                        !         : | + 2 ExecScanFetch  (in 
postgres) + 123  [0x110104bfb]
                                        !         : | 51 ExecProcNode  (in 
postgres) + 6,56,...  [0x1100fd536,0x1100fd568,...]
                                        !         : | 2 ExecFunctionScan  (in 
postgres) + 19  [0x110119ca3]
                                        !         : 1329 standard_ExecutorRun  
(in postgres) + 330  [0x1100f9a6a]
                                        !         : | 529 PLy_CSreceive  (in 
plpython2.so) + 368  [0x1108c4d50]
                                        !         : | + 517 PyInt_FromLong  (in 
Python) + 162,158,...  [0x119825a92,0x119825a8e,...]
                                        !         : | + 12 PLyInt_FromInt32  
(in plpython2.so) + 4,0  [0x1108c78c4,0x1108c78c0]
                                        !         : | 325 PLy_CSreceive  (in 
plpython2.so) + 454,226,...  [0x1108c4da6,0x1108c4cc2,...]
                                        !         : | 314 PLy_CSreceive  (in 
plpython2.so) + 466  [0x1108c4db2]
                                        !         : | + 300 PyList_Append  (in 
Python) + 149,43,...  [0x119829635,0x1198295cb,...]
                                        !         : | + 14 PyList_Append  (in 
Python) + 259  [0x1198296a3]
                                        !         : | +   14 realloc  (in 
libsystem_malloc.dylib) + 214  [0x7fff9a57a70a]
                                        !         : | +     14 
malloc_zone_realloc  (in libsystem_malloc.dylib) + 78  [0x7fff9a57a7eb]
                                        !         : | +       5 szone_realloc  
(in libsystem_malloc.dylib) + 1014  [0x7fff9a57ac12]
                                        !         : | +       : 5 free_large  
(in libsystem_malloc.dylib) + 729  [0x7fff9a57de87]
                                        !         : | +       :   5 
deallocate_pages  (in libsystem_malloc.dylib) + 74  [0x7fff9a57ec07]
                                        !         : | +       :     5 
mach_vm_deallocate  (in libsystem_kernel.dylib) + 25  [0x7fff8df91c2b]
                                        !         : | +       :       5 
_kernelrpc_mach_vm_deallocate_trap  (in libsystem_kernel.dylib) + 10  
[0x7fff8df8cea6]
                                        !         : | +       5 szone_realloc  
(in libsystem_malloc.dylib) + 1800  [0x7fff9a57af24]
                                        !         : | +       : 5 vm_allocate  
(in libsystem_kernel.dylib) + 25  [0x7fff8df91ce3]
                                        !         : | +       :   5 
mach_vm_allocate  (in libsystem_kernel.dylib) + 30  [0x7fff8df91bba]
                                        !         : | +       :     5 
_kernelrpc_mach_vm_allocate_trap  (in libsystem_kernel.dylib) + 10  
[0x7fff8df8ce9a]
                                        !         : | +       4 szone_realloc  
(in libsystem_malloc.dylib) + 985  [0x7fff9a57abf5]
                                        !         : | +         4 vm_copy  (in 
libsystem_kernel.dylib) + 97  [0x7fff8df8af6d]
                                        !         : | +           4 mach_msg  
(in libsystem_kernel.dylib) + 55  [0x7fff8df8c3b3]
                                        !         : | +             4 
mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff8df8cf72]
                                        !         : | 68 _setjmp  (in 
libsystem_platform.dylib) + 27,47,...  [0x7fff9aa2734f,0x7fff9aa27363,...]
                                        !         : | 25 PLy_CSreceive  (in 
plpython2.so) + 136  [0x1108c4c68]
                                        !         : | + 25 slot_getallattrs  
(in postgres) + 0,161,...  [0x10ff9cba0,0x10ff9cc41,...]
                                        !         : | 19 PLy_CSreceive  (in 
plpython2.so) + 101  [0x1108c4c45]
                                        !         : | + 19 
PLy_get_scratch_context  (in plpython2.so) + 0,62,...  
[0x1108c1260,0x1108c129e,...]
                                        !         : | 13 PLy_CSreceive  (in 
plpython2.so) + 570  [0x1108c4e1a]
                                        !         : | + 13 MemoryContextReset  
(in postgres) + 85,91,...  [0x11034dfe5,0x11034dfeb,...]
                                        !         : | 8 DYLD-STUB$$sigsetjmp  
(in plpython2.so) + 0  [0x1108c82d0]
                                        !         : | 8 
PLy_switch_execution_context  (in plpython2.so) + 0,7  [0x1108c1210,0x1108c1217]
                                        !         : | 7 setjmp  (in 
libsystem_platform.dylib) + 64  [0x7fff9aa272ec]
                                        !         : | 6 sigsetjmp  (in 
libsystem_platform.dylib) + 0,3  [0x7fff9aa27298,0x7fff9aa2729b]
                                        !         : | 3 
DYLD-STUB$$PyList_Append  (in plpython2.so) + 0  [0x1108c81aa]
                                        !         : | 1 
DYLD-STUB$$PyInt_FromLong  (in plpython2.so) + 0  [0x1108c819e]
                                        !         : | 1 PLyInt_FromInt32  (in 
plpython2.so) + 8  [0x1108c78c8]
                                        !         : | 1 PLy_CSreceive  (in 
plpython2.so) + 85  [0x1108c4c35]
                                        !         : | + 1 
PLy_switch_execution_context  (in plpython2.so) + 19  [0x1108c1223]
                                        !         : | 1 PLy_CSreceive  (in 
plpython2.so) + 582  [0x1108c4e26]
                                        !         : |   1 
PLy_switch_execution_context  (in plpython2.so) + 19  [0x1108c1223]
                                        !         : 22 standard_ExecutorRun  
(in postgres) + 356,322,...  [0x1100f9a84,0x1100f9a62,...]
                                        !         4 _SPI_execute_plan  (in 
postgres) + 1368  [0x110125468]
                                        !           4 standard_ExecutorEnd  (in 
postgres) + 50  [0x1100f9c52]
                                        !             4 ExecEndFunctionScan  
(in postgres) + 127  [0x11011a44f]
                                        !               4 tuplestore_end  (in 
postgres) + 24  [0x11035a5c8]
                                        !                 4 BufFileClose  (in 
postgres) + 63  [0x1101f3e4f]
                                        !                   4 FileClose  (in 
postgres) + 204  [0x1101f1dbc]
                                        !                     4 unlink  (in 
libsystem_kernel.dylib) + 11  [0x7fff8df90d28]
                                        !                       4 __unlink  (in 
libsystem_kernel.dylib) + 10  [0x7fff8df934fa]
                                        597 fast_function  (in Python) + 360  
[0x1198a83e8]
                                          597 frame_dealloc  (in Python) + 116  
[0x119823364]
                                            597 dict_dealloc  (in Python) + 153 
 [0x11983b399]
                                              535 list_dealloc  (in Python) + 
116,103,...  [0x11982b1b4,0x11982b1a7,...]
                                              59 list_dealloc  (in Python) + 
134  [0x11982b1c6]
                                              : 59 int_dealloc  (in Python) + 
0,34,...  [0x1198266f0,0x119826712,...]
                                              3 list_dealloc  (in Python) + 148 
 [0x11982b1d4]
                                                3 free_large  (in 
libsystem_malloc.dylib) + 729  [0x7fff9a57de87]
                                                  3 deallocate_pages  (in 
libsystem_malloc.dylib) + 74  [0x7fff9a57ec07]
                                                    3 mach_vm_deallocate  (in 
libsystem_kernel.dylib) + 25  [0x7fff8df91c2b]
                                                      3 
_kernelrpc_mach_vm_deallocate_trap  (in libsystem_kernel.dylib) + 10  
[0x7fff8df8cea6]

Total number in stack (recursive counted multiple, when >=5):

Sort by top of stack, same collapsed (when >= 5):
        poll  (in libsystem_kernel.dylib)        4996
        list_dealloc  (in Python)        535
        PyInt_FromLong  (in Python)        517
        PLy_CSreceive  (in plpython2.so)        325
        PyList_Append  (in Python)        300
        ExecProject  (in postgres)        148
        AllocSetAlloc  (in postgres)        125
        BufFileWrite  (in postgres)        118
        write  (in libsystem_kernel.dylib)        114
        BufFileRead  (in postgres)        111
        _platform_memmove$VARIANT$Haswell  (in libsystem_platform.dylib)        
106
        read  (in libsystem_kernel.dylib)        81
        slot_deform_tuple  (in postgres)        72
        _setjmp  (in libsystem_platform.dylib)        68
        ExecScan  (in postgres)        67
        GetMemoryChunkSpace  (in postgres)        66
        heap_fill_tuple  (in postgres)        61
        generate_series_step_int4  (in postgres)        60
        int_dealloc  (in Python)        59
        AllocSetFree  (in postgres)        57
        heap_form_minimal_tuple  (in postgres)        54
        ExecProcNode  (in postgres)        51
        MemoryContextReset  (in postgres)        48
        heap_compute_data_size  (in postgres)        47
        ExecClearTuple  (in postgres)        46
        getlen  (in postgres)        45
        ExecStoreMinimalTuple  (in postgres)        39
        palloc0  (in postgres)        37
        readtup_heap  (in postgres)        37
        _platform_bzero$VARIANT$Haswell  (in libsystem_platform.dylib)        36
        slot_getsomeattrs  (in postgres)        36
        writetup_heap  (in postgres)        34
        ExecMakeTableFunctionResult  (in postgres)        32
        tuplestore_puttuple_common  (in postgres)        32
        tuplestore_gettuple  (in postgres)        28
        tuplestore_putvalues  (in postgres)        28
        pfree  (in postgres)        25
        pgstat_init_function_usage  (in postgres)        25
        slot_getallattrs  (in postgres)        25
        palloc  (in postgres)        23
        tuplestore_gettupleslot  (in postgres)        23
        ExecScanFetch  (in postgres)        22
        FunctionNext  (in postgres)        22
        standard_ExecutorRun  (in postgres)        22
        pgstat_end_function_usage  (in postgres)        20
        PLy_get_scratch_context  (in plpython2.so)        19
        heap_free_minimal_tuple  (in postgres)        18
        AllocSetGetChunkSpace  (in postgres)        15
        ExecStoreVirtualTuple  (in postgres)        13
        PLyInt_FromInt32  (in plpython2.so)        13
        PLy_switch_execution_context  (in plpython2.so)        10
        per_MultiFuncCall  (in postgres)        9
        DYLD-STUB$$sigsetjmp  (in plpython2.so)        8
        _kernelrpc_mach_vm_deallocate_trap  (in libsystem_kernel.dylib)        8
        DYLD-STUB$$memcpy  (in postgres)        7
        ExecFunctionScan  (in postgres)        7
        generate_series_int4  (in postgres)        7
        setjmp  (in libsystem_platform.dylib)        7
        sigsetjmp  (in libsystem_platform.dylib)        6
        _kernelrpc_mach_vm_allocate_trap  (in libsystem_kernel.dylib)        5

Binary Images:
       0x10ff94000 -        0x1104acff7 +postgres (0) 
<3CF1BFB1-85FB-34FC-903E-C3E25DE1E31B> /Users/decibel/pgsql/HEAD/i/bin/postgres
       0x1105c5000 -        0x1106b7fff +libxml2.2.dylib (0) 
<C7BE0668-4145-39EC-989D-CC100B1AB7B3> /opt/local/lib/libxml2.2.dylib
       0x1106f0000 -        0x110700fff +libz.1.dylib (0) 
<5FCFF38B-5983-3590-B5E9-074CF0950676> /opt/local/lib/libz.1.dylib
       0x110704000 -        0x110720ff7 +liblzma.5.dylib (0) 
<891E9115-3D51-3042-94E6-7BD0EBA4448C> /opt/local/lib/liblzma.5.dylib
       0x110726000 -        0x110728fff +_locale.so (0) 
<69126147-6797-3C06-8573-E2BE8B05F0E8> 
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_locale.so
       0x11072c000 -        0x110820fff +libiconv.2.dylib (0) 
<FE5F439D-596E-31C7-9AB8-154010F30914> /opt/local/lib/libiconv.2.dylib
       0x1108bb000 -        0x1108cdffb +plpython2.so (0) 
<D7DC6B28-32D2-39A6-B4FC-558C3E4F7253> 
/Users/decibel/pgsql/HEAD/i/lib/plpython2.so
       0x110a47000 -        0x110a50fff +libintl.8.dylib (0) 
<6C3DC2F0-96B8-37D8-81EF-D85A680D5245> /opt/local/lib/libintl.8.dylib
       0x1197ef000 -        0x119923ff7 +org.python.python (2.7.13, [c] 
2001-2016 Python Software Foundation. - 2.7.13) 
<F78FB146-2DD1-34FE-93A8-BA1D9D8105F8> 
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python
    0x7fff6fa51000 -     0x7fff6fa88a47  dyld (0.0 - ???) 
<884763FC-CC0F-31CC-ACC4-75A805CE401D> /usr/lib/dyld
    0x7fff8b54e000 -     0x7fff8b556fff  libcopyfile.dylib (127) 
<A48637BC-F3F2-34F2-BB68-4C65FD012832> /usr/lib/system/libcopyfile.dylib
    0x7fff8b60c000 -     0x7fff8b635fff  libsystem_info.dylib (477.50.4) 
<FAA9226D-64DE-3769-A6D8-6CABA4B7FF4D> /usr/lib/system/libsystem_info.dylib
    0x7fff8bf81000 -     0x7fff8bf92ff7  libz.1.dylib (61.20.1) 
<B3EBB42F-48E3-3287-9F0D-308E04D407AC> /usr/lib/libz.1.dylib
    0x7fff8bfcb000 -     0x7fff8c01eff7  libc++.1.dylib (120.1) 
<8FC3D139-8055-3498-9AC5-6467CB7F4D14> /usr/lib/libc++.1.dylib
    0x7fff8c04a000 -     0x7fff8c04fff7  libmacho.dylib (875.1) 
<318264FA-58F1-39D8-8285-1F6254EE410E> /usr/lib/system/libmacho.dylib
    0x7fff8c3b8000 -     0x7fff8c3bbffb  libdyld.dylib (360.22) 
<F103B2FB-D383-38CB-992A-E16BDCB00A03> /usr/lib/system/libdyld.dylib
    0x7fff8d17c000 -     0x7fff8d184ffb  libsystem_dnssd.dylib (625.60.4) 
<80189998-32B0-316C-B5C5-53857486713D> /usr/lib/system/libsystem_dnssd.dylib
    0x7fff8d7fc000 -     0x7fff8d7fdffb  libSystem.B.dylib (1226.10.1) 
<012548CD-614D-3AF0-B3B1-676F427D2CD6> /usr/lib/libSystem.B.dylib
    0x7fff8d9ad000 -     0x7fff8da13ff7  libsystem_network.dylib (583.50.1) 
<B52DAB73-92DC-3DA7-B9F4-B899D66445C1> /usr/lib/system/libsystem_network.dylib
    0x7fff8dcd4000 -     0x7fff8dcd6ff7  libquarantine.dylib (80) 
<0F4169F0-0C84-3A25-B3AE-E47B3586D908> /usr/lib/system/libquarantine.dylib
    0x7fff8df7c000 -     0x7fff8df9aff7  libsystem_kernel.dylib 
(3248.60.11.1.2) <1CC38FFB-EB7B-340D-AC32-27580A15AC0A> 
/usr/lib/system/libsystem_kernel.dylib
    0x7fff8f5f8000 -     0x7fff8fa6eff7  com.apple.CoreFoundation (6.9 - 1259) 
<51D1F34F-9FEC-3EF2-8382-2D13D75F845A> 
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    0x7fff8fc83000 -     0x7fff8fc8bfff  libsystem_networkextension.dylib 
(385.40.36) <66095DC7-6539-38F2-95EE-458F15F6D014> 
/usr/lib/system/libsystem_networkextension.dylib
    0x7fff90a94000 -     0x7fff90ca1fff  libicucore.A.dylib (551.51.4) 
<3899B146-3840-3D4A-8C4A-FE391D5D25C7> /usr/lib/libicucore.A.dylib
    0x7fff90e41000 -     0x7fff90e41ff7  libkeymgr.dylib (28) 
<8371CE54-5FDD-3CE9-B3DF-E98C761B6FE0> /usr/lib/system/libkeymgr.dylib
    0x7fff911ab000 -     0x7fff911b2ff7  libcompiler_rt.dylib (62) 
<A13ECF69-F59F-38AE-8609-7B731450FBCD> /usr/lib/system/libcompiler_rt.dylib
    0x7fff9138b000 -     0x7fff9138cfff  libsystem_blocks.dylib (65) 
<1244D9D5-F6AA-35BB-B307-86851C24B8E5> /usr/lib/system/libsystem_blocks.dylib
    0x7fff91921000 -     0x7fff91950ffb  libsystem_m.dylib (3105) 
<08E1A4B2-6448-3DFE-A58C-ACC7335BE7E4> /usr/lib/system/libsystem_m.dylib
    0x7fff91ccf000 -     0x7fff91cd0ffb  libremovefile.dylib (41) 
<552EF39E-14D7-363E-9059-4565AC2F894E> /usr/lib/system/libremovefile.dylib
    0x7fff91cd1000 -     0x7fff91ce2ff7  libsystem_trace.dylib (201.10.3) 
<E9311C03-9E61-3B13-AF3F-A64956FFF269> /usr/lib/system/libsystem_trace.dylib
    0x7fff92388000 -     0x7fff923fffeb  libcorecrypto.dylib (335.50.1) 
<B5C05FD7-A540-345A-87BF-8E41848A3C17> /usr/lib/system/libcorecrypto.dylib
    0x7fff925db000 -     0x7fff925dffff  libcache.dylib (75) 
<9548AAE9-2AB7-3525-9ECE-A2A7C4688447> /usr/lib/system/libcache.dylib
    0x7fff9360d000 -     0x7fff9360dff7  libunc.dylib (29) 
<DDB1E947-C775-33B8-B461-63E5EB698F0E> /usr/lib/system/libunc.dylib
    0x7fff93ede000 -     0x7fff93edffff  libsystem_secinit.dylib (20) 
<32B1A8C6-DC84-3F4F-B8CE-9A52B47C3E6B> /usr/lib/system/libsystem_secinit.dylib
    0x7fff94345000 -     0x7fff94347fff  libsystem_coreservices.dylib (19.2) 
<1B3F5AFC-FFCD-3ECB-8B9A-5538366FB20D> 
/usr/lib/system/libsystem_coreservices.dylib
    0x7fff943e9000 -     0x7fff943eeff3  libunwind.dylib (35.3) 
<F6EB48E5-4D12-359A-AB54-C937FBBE9043> /usr/lib/system/libunwind.dylib
    0x7fff946e6000 -     0x7fff9470fff7  libxpc.dylib (765.50.8) 
<54D1328E-054E-3DAA-89E2-375722F9D18F> /usr/lib/system/libxpc.dylib
    0x7fff969b1000 -     0x7fff969f7ff7  libauto.dylib (186) 
<999E610F-41FC-32A3-ADCA-5EC049B65DFB> /usr/lib/libauto.dylib
    0x7fff96c2c000 -     0x7fff96c2dfff  libDiagnosticMessagesClient.dylib 
(100) <4243B6B4-21E9-355B-9C5A-95A216233B96> 
/usr/lib/libDiagnosticMessagesClient.dylib
    0x7fff96c2e000 -     0x7fff96c37ff3  libsystem_notify.dylib (150.40.1) 
<D48BDE34-0F7E-34CA-A0FF-C578E39987CC> /usr/lib/system/libsystem_notify.dylib
    0x7fff96d54000 -     0x7fff96d57fff  libsystem_sandbox.dylib (460.60.2) 
<2A68B39C-B786-3A05-87A2-56E688469FB8> /usr/lib/system/libsystem_sandbox.dylib
    0x7fff986b5000 -     0x7fff986b5ff7  liblaunch.dylib (765.50.8) 
<834ED605-5114-3641-AA4D-ECF31B801C50> /usr/lib/system/liblaunch.dylib
    0x7fff98872000 -     0x7fff98889ff7  libsystem_asl.dylib (323.50.1) 
<41F8E11F-1BD0-3F1D-BA3A-AA1577ED98A9> /usr/lib/system/libsystem_asl.dylib
    0x7fff98bfe000 -     0x7fff98c2bfff  libdispatch.dylib (501.40.12) 
<C7499857-61A5-3D7D-A5EA-65DCC8C3DF92> /usr/lib/system/libdispatch.dylib
    0x7fff992ea000 -     0x7fff992f3ff7  libsystem_pthread.dylib (138.10.4) 
<3DD1EF4C-1D1B-3ABF-8CC6-B3B1CEEE9559> /usr/lib/system/libsystem_pthread.dylib
    0x7fff9a1df000 -     0x7fff9a541f3f  libobjc.A.dylib (680) 
<7489D2D6-1EFD-3414-B18D-2AECCCC90286> /usr/lib/libobjc.A.dylib
    0x7fff9a574000 -     0x7fff9a590ff7  libsystem_malloc.dylib (67.40.1) 
<5748E8B2-F81C-34C6-8B13-456213127678> /usr/lib/system/libsystem_malloc.dylib
    0x7fff9a7f2000 -     0x7fff9a7fdff7  libcommonCrypto.dylib (60075.50.1) 
<93732261-34B4-3914-B7A2-90A81A182DBA> /usr/lib/system/libcommonCrypto.dylib
    0x7fff9aa25000 -     0x7fff9aa2dfef  libsystem_platform.dylib (74.40.2) 
<29A905EF-6777-3C33-82B0-6C3A88C4BA15> /usr/lib/system/libsystem_platform.dylib
    0x7fff9b631000 -     0x7fff9b648ff7  libsystem_coretls.dylib (83.40.5) 
<C90DAE38-4082-381C-A185-2A6A8B677628> /usr/lib/system/libsystem_coretls.dylib
    0x7fff9b827000 -     0x7fff9b8b4fef  libsystem_c.dylib (1082.60.1) 
<28733D22-553E-3CBC-8D2C-EDCEB46E46AF> /usr/lib/system/libsystem_c.dylib
    0x7fff9e09e000 -     0x7fff9e0a0ff7  libsystem_configuration.dylib 
(802.40.13) <3DEB7DF9-6804-37E1-BC83-0166882FF0FF> 
/usr/lib/system/libsystem_configuration.dylib
    0x7fff9ecc2000 -     0x7fff9ececff7  libc++abi.dylib (307.2) 
<922EFB36-0E9E-315B-8270-E81AC43472C0> /usr/lib/libc++abi.dylib
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to