Обсуждение: strange tuple from ExecutorRun

Поиск
Список
Период
Сортировка

strange tuple from ExecutorRun

От
"Pavel Stehule"
Дата:
Hello

I cannot find my bug. I would to get tuple via ExecutorRun. But it
works only with one field in target. With more fields I got last
fileld on first position and others fields are null. Can somebody help
me?

Pavel Stehule

postgres=# call print(10,20,30);
NOTICE:  nargs 3
NOTICE:  30 0
NOTICE:  2139062143 0
NOTICE:  2139062143 0



code:               dest = CreateDestReceiver(DestNone, NULL);
               ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
               qdesc = CreateQueryDesc(plan, ActiveSnapshot,
InvalidSnapshot,                                                      dest,
         paramLI, false);
 
               ExecutorStart(qdesc, 0);
               result = ExecutorRun(qdesc, ForwardScanDirection, 1L);
               tuple = ExecMaterializeSlot(result);
               values = (Datum *) palloc(nargs * sizeof(Datum));               nulls = (char *) palloc(nargs *
sizeof(char));
               /* copy typle to current context */               tuple = heap_copytuple(tuple);

               heap_deform_tuple(tuple, qdesc->tupDesc, values, nulls);
               for(i = 0; i < nargs; i++)               elog(NOTICE, "%d %d", values[i], nulls[i]);


NOTICE:  plan:
DETAIL:     {PLANNEDSTMT  :commandType 1  :canSetTag true  :planTree     {RESULT     :startup_cost 0.00     :total_cost
0.01    :plan_rows 1     :plan_width 0     :targetlist (        {TARGETENTRY        :expr           {CONST
:consttype23           :consttypmod -1           :constlen 4           :constbyval true           :constisnull false
      :constvalue 4 [ 10 0 0 0 ]           }        :resno 1        :resname ?Parameter?        :ressortgroupref 0
 :resorigtbl 0        :resorigcol 0        :resjunk false        }        {TARGETENTRY        :expr           {CONST
      :consttype 23           :consttypmod -1           :constlen 4           :constbyval true           :constisnull
false          :constvalue 4 [ 20 0 0 0 ]           }        :resno 1        :resname ?Parameter?
:ressortgroupref0        :resorigtbl 0        :resorigcol 0        :resjunk false        }        {TARGETENTRY
:expr          {CONST           :consttype 23           :consttypmod -1           :constlen 4           :constbyval
true          :constisnull false           :constvalue 4 [ 30 0 0 0 ]           }        :resno 1        :resname
?Parameter?       :ressortgroupref 0        :resorigtbl 0        :resorigcol 0        :resjunk false        }     )
:qual<>     :lefttree <>     :righttree <>     :initPlan <>     :extParam (b)     :allParam (b)     :resconstantqual <>
   }  :rtable <>  :resultRelations <>  :utilityStmt <>  :intoClause <>  :subplans <>  :rewindPlanIDs (b)
:returningLists<>  :rowMarks <>  :relationOids <>  :nParamExec 0  }
 


Re: strange tuple from ExecutorRun

От
Tom Lane
Дата:
[ not directly related to your bug, but... ]

"Pavel Stehule" <pavel.stehule@gmail.com> writes:
>                 result = ExecutorRun(qdesc, ForwardScanDirection, 1L);

>                 tuple = ExecMaterializeSlot(result);

>                 values = (Datum *) palloc(nargs * sizeof(Datum));
>                 nulls = (char *) palloc(nargs * sizeof(char));

>                 /* copy typle to current context */
>                 tuple = heap_copytuple(tuple);

>                 heap_deform_tuple(tuple, qdesc->tupDesc, values, nulls);

Surely that's the hard way, considering that the output tupleslot is
probably *already* a values/nulls array.  Use slot_getattr(), or call
slot_getallattrs() and then reference the slot's arrays directly.
        regards, tom lane