00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #include "postgres.h"
00090
00091 #include "access/htup_details.h"
00092 #include "funcapi.h"
00093 #include "catalog/pg_type.h"
00094 #include "nodes/nodeFuncs.h"
00095 #include "storage/bufmgr.h"
00096 #include "utils/builtins.h"
00097 #include "utils/lsyscache.h"
00098 #include "utils/typcache.h"
00099
00100
00101 static TupleDesc ExecTypeFromTLInternal(List *targetList,
00102 bool hasoid, bool skipjunk);
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 TupleTableSlot *
00117 MakeTupleTableSlot(void)
00118 {
00119 TupleTableSlot *slot = makeNode(TupleTableSlot);
00120
00121 slot->tts_isempty = true;
00122 slot->tts_shouldFree = false;
00123 slot->tts_shouldFreeMin = false;
00124 slot->tts_tuple = NULL;
00125 slot->tts_tupleDescriptor = NULL;
00126 slot->tts_mcxt = CurrentMemoryContext;
00127 slot->tts_buffer = InvalidBuffer;
00128 slot->tts_nvalid = 0;
00129 slot->tts_values = NULL;
00130 slot->tts_isnull = NULL;
00131 slot->tts_mintuple = NULL;
00132
00133 return slot;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 TupleTableSlot *
00143 ExecAllocTableSlot(List **tupleTable)
00144 {
00145 TupleTableSlot *slot = MakeTupleTableSlot();
00146
00147 *tupleTable = lappend(*tupleTable, slot);
00148
00149 return slot;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 void
00162 ExecResetTupleTable(List *tupleTable,
00163 bool shouldFree)
00164 {
00165 ListCell *lc;
00166
00167 foreach(lc, tupleTable)
00168 {
00169 TupleTableSlot *slot = (TupleTableSlot *) lfirst(lc);
00170
00171
00172 Assert(IsA(slot, TupleTableSlot));
00173
00174
00175 ExecClearTuple(slot);
00176 if (slot->tts_tupleDescriptor)
00177 {
00178 ReleaseTupleDesc(slot->tts_tupleDescriptor);
00179 slot->tts_tupleDescriptor = NULL;
00180 }
00181
00182
00183 if (shouldFree)
00184 {
00185 if (slot->tts_values)
00186 pfree(slot->tts_values);
00187 if (slot->tts_isnull)
00188 pfree(slot->tts_isnull);
00189 pfree(slot);
00190 }
00191 }
00192
00193
00194 if (shouldFree)
00195 list_free(tupleTable);
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 TupleTableSlot *
00208 MakeSingleTupleTableSlot(TupleDesc tupdesc)
00209 {
00210 TupleTableSlot *slot = MakeTupleTableSlot();
00211
00212 ExecSetSlotDescriptor(slot, tupdesc);
00213
00214 return slot;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224 void
00225 ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
00226 {
00227
00228 Assert(IsA(slot, TupleTableSlot));
00229 ExecClearTuple(slot);
00230 if (slot->tts_tupleDescriptor)
00231 ReleaseTupleDesc(slot->tts_tupleDescriptor);
00232 if (slot->tts_values)
00233 pfree(slot->tts_values);
00234 if (slot->tts_isnull)
00235 pfree(slot->tts_isnull);
00236 pfree(slot);
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 void
00256 ExecSetSlotDescriptor(TupleTableSlot *slot,
00257 TupleDesc tupdesc)
00258 {
00259
00260 ExecClearTuple(slot);
00261
00262
00263
00264
00265
00266 if (slot->tts_tupleDescriptor)
00267 ReleaseTupleDesc(slot->tts_tupleDescriptor);
00268
00269 if (slot->tts_values)
00270 pfree(slot->tts_values);
00271 if (slot->tts_isnull)
00272 pfree(slot->tts_isnull);
00273
00274
00275
00276
00277 slot->tts_tupleDescriptor = tupdesc;
00278 PinTupleDesc(tupdesc);
00279
00280
00281
00282
00283
00284 slot->tts_values = (Datum *)
00285 MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
00286 slot->tts_isnull = (bool *)
00287 MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(bool));
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 TupleTableSlot *
00329 ExecStoreTuple(HeapTuple tuple,
00330 TupleTableSlot *slot,
00331 Buffer buffer,
00332 bool shouldFree)
00333 {
00334
00335
00336
00337 Assert(tuple != NULL);
00338 Assert(slot != NULL);
00339 Assert(slot->tts_tupleDescriptor != NULL);
00340
00341 Assert(BufferIsValid(buffer) ? (!shouldFree) : true);
00342
00343
00344
00345
00346 if (slot->tts_shouldFree)
00347 heap_freetuple(slot->tts_tuple);
00348 if (slot->tts_shouldFreeMin)
00349 heap_free_minimal_tuple(slot->tts_mintuple);
00350
00351
00352
00353
00354 slot->tts_isempty = false;
00355 slot->tts_shouldFree = shouldFree;
00356 slot->tts_shouldFreeMin = false;
00357 slot->tts_tuple = tuple;
00358 slot->tts_mintuple = NULL;
00359
00360
00361 slot->tts_nvalid = 0;
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 if (slot->tts_buffer != buffer)
00373 {
00374 if (BufferIsValid(slot->tts_buffer))
00375 ReleaseBuffer(slot->tts_buffer);
00376 slot->tts_buffer = buffer;
00377 if (BufferIsValid(buffer))
00378 IncrBufferRefCount(buffer);
00379 }
00380
00381 return slot;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 TupleTableSlot *
00393 ExecStoreMinimalTuple(MinimalTuple mtup,
00394 TupleTableSlot *slot,
00395 bool shouldFree)
00396 {
00397
00398
00399
00400 Assert(mtup != NULL);
00401 Assert(slot != NULL);
00402 Assert(slot->tts_tupleDescriptor != NULL);
00403
00404
00405
00406
00407 if (slot->tts_shouldFree)
00408 heap_freetuple(slot->tts_tuple);
00409 if (slot->tts_shouldFreeMin)
00410 heap_free_minimal_tuple(slot->tts_mintuple);
00411
00412
00413
00414
00415 if (BufferIsValid(slot->tts_buffer))
00416 ReleaseBuffer(slot->tts_buffer);
00417
00418 slot->tts_buffer = InvalidBuffer;
00419
00420
00421
00422
00423 slot->tts_isempty = false;
00424 slot->tts_shouldFree = false;
00425 slot->tts_shouldFreeMin = shouldFree;
00426 slot->tts_tuple = &slot->tts_minhdr;
00427 slot->tts_mintuple = mtup;
00428
00429 slot->tts_minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
00430 slot->tts_minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
00431
00432
00433
00434 slot->tts_nvalid = 0;
00435
00436 return slot;
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 TupleTableSlot *
00448 ExecClearTuple(TupleTableSlot *slot)
00449 {
00450
00451
00452
00453 Assert(slot != NULL);
00454
00455
00456
00457
00458 if (slot->tts_shouldFree)
00459 heap_freetuple(slot->tts_tuple);
00460 if (slot->tts_shouldFreeMin)
00461 heap_free_minimal_tuple(slot->tts_mintuple);
00462
00463 slot->tts_tuple = NULL;
00464 slot->tts_mintuple = NULL;
00465 slot->tts_shouldFree = false;
00466 slot->tts_shouldFreeMin = false;
00467
00468
00469
00470
00471 if (BufferIsValid(slot->tts_buffer))
00472 ReleaseBuffer(slot->tts_buffer);
00473
00474 slot->tts_buffer = InvalidBuffer;
00475
00476
00477
00478
00479 slot->tts_isempty = true;
00480 slot->tts_nvalid = 0;
00481
00482 return slot;
00483 }
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496 TupleTableSlot *
00497 ExecStoreVirtualTuple(TupleTableSlot *slot)
00498 {
00499
00500
00501
00502 Assert(slot != NULL);
00503 Assert(slot->tts_tupleDescriptor != NULL);
00504 Assert(slot->tts_isempty);
00505
00506 slot->tts_isempty = false;
00507 slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
00508
00509 return slot;
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520 TupleTableSlot *
00521 ExecStoreAllNullTuple(TupleTableSlot *slot)
00522 {
00523
00524
00525
00526 Assert(slot != NULL);
00527 Assert(slot->tts_tupleDescriptor != NULL);
00528
00529
00530 ExecClearTuple(slot);
00531
00532
00533
00534
00535 MemSet(slot->tts_values, 0,
00536 slot->tts_tupleDescriptor->natts * sizeof(Datum));
00537 memset(slot->tts_isnull, true,
00538 slot->tts_tupleDescriptor->natts * sizeof(bool));
00539
00540 return ExecStoreVirtualTuple(slot);
00541 }
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553 HeapTuple
00554 ExecCopySlotTuple(TupleTableSlot *slot)
00555 {
00556
00557
00558
00559 Assert(slot != NULL);
00560 Assert(!slot->tts_isempty);
00561
00562
00563
00564
00565 if (TTS_HAS_PHYSICAL_TUPLE(slot))
00566 return heap_copytuple(slot->tts_tuple);
00567 if (slot->tts_mintuple)
00568 return heap_tuple_from_minimal_tuple(slot->tts_mintuple);
00569
00570
00571
00572
00573 return heap_form_tuple(slot->tts_tupleDescriptor,
00574 slot->tts_values,
00575 slot->tts_isnull);
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585 MinimalTuple
00586 ExecCopySlotMinimalTuple(TupleTableSlot *slot)
00587 {
00588
00589
00590
00591 Assert(slot != NULL);
00592 Assert(!slot->tts_isempty);
00593
00594
00595
00596
00597
00598 if (slot->tts_mintuple)
00599 return heap_copy_minimal_tuple(slot->tts_mintuple);
00600 if (slot->tts_tuple)
00601 return minimal_tuple_from_heap_tuple(slot->tts_tuple);
00602
00603
00604
00605
00606 return heap_form_minimal_tuple(slot->tts_tupleDescriptor,
00607 slot->tts_values,
00608 slot->tts_isnull);
00609 }
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626 HeapTuple
00627 ExecFetchSlotTuple(TupleTableSlot *slot)
00628 {
00629
00630
00631
00632 Assert(slot != NULL);
00633 Assert(!slot->tts_isempty);
00634
00635
00636
00637
00638 if (TTS_HAS_PHYSICAL_TUPLE(slot))
00639 return slot->tts_tuple;
00640
00641
00642
00643
00644 return ExecMaterializeSlot(slot);
00645 }
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 MinimalTuple
00661 ExecFetchSlotMinimalTuple(TupleTableSlot *slot)
00662 {
00663 MemoryContext oldContext;
00664
00665
00666
00667
00668 Assert(slot != NULL);
00669 Assert(!slot->tts_isempty);
00670
00671
00672
00673
00674 if (slot->tts_mintuple)
00675 return slot->tts_mintuple;
00676
00677
00678
00679
00680
00681
00682
00683
00684 oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
00685 slot->tts_mintuple = ExecCopySlotMinimalTuple(slot);
00686 slot->tts_shouldFreeMin = true;
00687 MemoryContextSwitchTo(oldContext);
00688
00689
00690
00691
00692
00693
00694
00695
00696 return slot->tts_mintuple;
00697 }
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 Datum
00709 ExecFetchSlotTupleDatum(TupleTableSlot *slot)
00710 {
00711 HeapTuple tup;
00712 HeapTupleHeader td;
00713 TupleDesc tupdesc;
00714
00715
00716 tup = ExecMaterializeSlot(slot);
00717
00718 td = tup->t_data;
00719 tupdesc = slot->tts_tupleDescriptor;
00720 HeapTupleHeaderSetDatumLength(td, tup->t_len);
00721 HeapTupleHeaderSetTypeId(td, tupdesc->tdtypeid);
00722 HeapTupleHeaderSetTypMod(td, tupdesc->tdtypmod);
00723 return PointerGetDatum(td);
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739 HeapTuple
00740 ExecMaterializeSlot(TupleTableSlot *slot)
00741 {
00742 MemoryContext oldContext;
00743
00744
00745
00746
00747 Assert(slot != NULL);
00748 Assert(!slot->tts_isempty);
00749
00750
00751
00752
00753
00754 if (slot->tts_tuple && slot->tts_shouldFree)
00755 return slot->tts_tuple;
00756
00757
00758
00759
00760
00761
00762
00763
00764 oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
00765 slot->tts_tuple = ExecCopySlotTuple(slot);
00766 slot->tts_shouldFree = true;
00767 MemoryContextSwitchTo(oldContext);
00768
00769
00770
00771
00772 if (BufferIsValid(slot->tts_buffer))
00773 ReleaseBuffer(slot->tts_buffer);
00774
00775 slot->tts_buffer = InvalidBuffer;
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785 slot->tts_nvalid = 0;
00786
00787
00788
00789
00790
00791
00792
00793 if (!slot->tts_shouldFreeMin)
00794 slot->tts_mintuple = NULL;
00795
00796 return slot->tts_tuple;
00797 }
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 TupleTableSlot *
00810 ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
00811 {
00812 HeapTuple newTuple;
00813 MemoryContext oldContext;
00814
00815
00816
00817
00818
00819
00820 oldContext = MemoryContextSwitchTo(dstslot->tts_mcxt);
00821 newTuple = ExecCopySlotTuple(srcslot);
00822 MemoryContextSwitchTo(oldContext);
00823
00824 return ExecStoreTuple(newTuple, dstslot, InvalidBuffer, true);
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846 void
00847 ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
00848 {
00849 planstate->ps_ResultTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable);
00850 }
00851
00852
00853
00854
00855
00856 void
00857 ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
00858 {
00859 scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable);
00860 }
00861
00862
00863
00864
00865
00866 TupleTableSlot *
00867 ExecInitExtraTupleSlot(EState *estate)
00868 {
00869 return ExecAllocTableSlot(&estate->es_tupleTable);
00870 }
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880 TupleTableSlot *
00881 ExecInitNullTupleSlot(EState *estate, TupleDesc tupType)
00882 {
00883 TupleTableSlot *slot = ExecInitExtraTupleSlot(estate);
00884
00885 ExecSetSlotDescriptor(slot, tupType);
00886
00887 return ExecStoreAllNullTuple(slot);
00888 }
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902 TupleDesc
00903 ExecTypeFromTL(List *targetList, bool hasoid)
00904 {
00905 return ExecTypeFromTLInternal(targetList, hasoid, false);
00906 }
00907
00908
00909
00910
00911
00912
00913
00914 TupleDesc
00915 ExecCleanTypeFromTL(List *targetList, bool hasoid)
00916 {
00917 return ExecTypeFromTLInternal(targetList, hasoid, true);
00918 }
00919
00920 static TupleDesc
00921 ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
00922 {
00923 TupleDesc typeInfo;
00924 ListCell *l;
00925 int len;
00926 int cur_resno = 1;
00927
00928 if (skipjunk)
00929 len = ExecCleanTargetListLength(targetList);
00930 else
00931 len = ExecTargetListLength(targetList);
00932 typeInfo = CreateTemplateTupleDesc(len, hasoid);
00933
00934 foreach(l, targetList)
00935 {
00936 TargetEntry *tle = lfirst(l);
00937
00938 if (skipjunk && tle->resjunk)
00939 continue;
00940 TupleDescInitEntry(typeInfo,
00941 cur_resno,
00942 tle->resname,
00943 exprType((Node *) tle->expr),
00944 exprTypmod((Node *) tle->expr),
00945 0);
00946 TupleDescInitEntryCollation(typeInfo,
00947 cur_resno,
00948 exprCollation((Node *) tle->expr));
00949 cur_resno++;
00950 }
00951
00952 return typeInfo;
00953 }
00954
00955
00956
00957
00958
00959
00960 TupleDesc
00961 ExecTypeFromExprList(List *exprList, List *namesList)
00962 {
00963 TupleDesc typeInfo;
00964 ListCell *le;
00965 ListCell *ln;
00966 int cur_resno = 1;
00967
00968 Assert(list_length(exprList) == list_length(namesList));
00969
00970 typeInfo = CreateTemplateTupleDesc(list_length(exprList), false);
00971
00972 forboth(le, exprList, ln, namesList)
00973 {
00974 Node *e = lfirst(le);
00975 char *n = strVal(lfirst(ln));
00976
00977 TupleDescInitEntry(typeInfo,
00978 cur_resno,
00979 n,
00980 exprType(e),
00981 exprTypmod(e),
00982 0);
00983 TupleDescInitEntryCollation(typeInfo,
00984 cur_resno,
00985 exprCollation(e));
00986 cur_resno++;
00987 }
00988
00989 return typeInfo;
00990 }
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000 TupleDesc
01001 BlessTupleDesc(TupleDesc tupdesc)
01002 {
01003 if (tupdesc->tdtypeid == RECORDOID &&
01004 tupdesc->tdtypmod < 0)
01005 assign_record_type_typmod(tupdesc);
01006
01007 return tupdesc;
01008 }
01009
01010
01011
01012
01013
01014
01015
01016
01017 TupleTableSlot *
01018 TupleDescGetSlot(TupleDesc tupdesc)
01019 {
01020 TupleTableSlot *slot;
01021
01022
01023 BlessTupleDesc(tupdesc);
01024
01025
01026 slot = MakeSingleTupleTableSlot(tupdesc);
01027
01028
01029 return slot;
01030 }
01031
01032
01033
01034
01035
01036
01037 AttInMetadata *
01038 TupleDescGetAttInMetadata(TupleDesc tupdesc)
01039 {
01040 int natts = tupdesc->natts;
01041 int i;
01042 Oid atttypeid;
01043 Oid attinfuncid;
01044 FmgrInfo *attinfuncinfo;
01045 Oid *attioparams;
01046 int32 *atttypmods;
01047 AttInMetadata *attinmeta;
01048
01049 attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
01050
01051
01052 attinmeta->tupdesc = BlessTupleDesc(tupdesc);
01053
01054
01055
01056
01057 attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
01058 attioparams = (Oid *) palloc0(natts * sizeof(Oid));
01059 atttypmods = (int32 *) palloc0(natts * sizeof(int32));
01060
01061 for (i = 0; i < natts; i++)
01062 {
01063
01064 if (!tupdesc->attrs[i]->attisdropped)
01065 {
01066 atttypeid = tupdesc->attrs[i]->atttypid;
01067 getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
01068 fmgr_info(attinfuncid, &attinfuncinfo[i]);
01069 atttypmods[i] = tupdesc->attrs[i]->atttypmod;
01070 }
01071 }
01072 attinmeta->attinfuncs = attinfuncinfo;
01073 attinmeta->attioparams = attioparams;
01074 attinmeta->atttypmods = atttypmods;
01075
01076 return attinmeta;
01077 }
01078
01079
01080
01081
01082
01083
01084 HeapTuple
01085 BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
01086 {
01087 TupleDesc tupdesc = attinmeta->tupdesc;
01088 int natts = tupdesc->natts;
01089 Datum *dvalues;
01090 bool *nulls;
01091 int i;
01092 HeapTuple tuple;
01093
01094 dvalues = (Datum *) palloc(natts * sizeof(Datum));
01095 nulls = (bool *) palloc(natts * sizeof(bool));
01096
01097
01098 for (i = 0; i < natts; i++)
01099 {
01100 if (!tupdesc->attrs[i]->attisdropped)
01101 {
01102
01103 dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
01104 values[i],
01105 attinmeta->attioparams[i],
01106 attinmeta->atttypmods[i]);
01107 if (values[i] != NULL)
01108 nulls[i] = false;
01109 else
01110 nulls[i] = true;
01111 }
01112 else
01113 {
01114
01115 dvalues[i] = (Datum) 0;
01116 nulls[i] = true;
01117 }
01118 }
01119
01120
01121
01122
01123 tuple = heap_form_tuple(tupdesc, dvalues, nulls);
01124
01125
01126
01127
01128
01129 pfree(dvalues);
01130 pfree(nulls);
01131
01132 return tuple;
01133 }
01134
01135
01136
01137
01138
01139
01140
01141 TupOutputState *
01142 begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc)
01143 {
01144 TupOutputState *tstate;
01145
01146 tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
01147
01148 tstate->slot = MakeSingleTupleTableSlot(tupdesc);
01149 tstate->dest = dest;
01150
01151 (*tstate->dest->rStartup) (tstate->dest, (int) CMD_SELECT, tupdesc);
01152
01153 return tstate;
01154 }
01155
01156
01157
01158
01159 void
01160 do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
01161 {
01162 TupleTableSlot *slot = tstate->slot;
01163 int natts = slot->tts_tupleDescriptor->natts;
01164
01165
01166 ExecClearTuple(slot);
01167
01168
01169 memcpy(slot->tts_values, values, natts * sizeof(Datum));
01170 memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
01171
01172
01173 ExecStoreVirtualTuple(slot);
01174
01175
01176 (*tstate->dest->receiveSlot) (slot, tstate->dest);
01177
01178
01179 ExecClearTuple(slot);
01180 }
01181
01182
01183
01184
01185
01186
01187 void
01188 do_text_output_multiline(TupOutputState *tstate, char *text)
01189 {
01190 Datum values[1];
01191 bool isnull[1] = {false};
01192
01193 while (*text)
01194 {
01195 char *eol;
01196 int len;
01197
01198 eol = strchr(text, '\n');
01199 if (eol)
01200 {
01201 len = eol - text;
01202
01203 eol++;
01204 }
01205 else
01206 {
01207 len = strlen(text);
01208 eol += len;
01209 }
01210
01211 values[0] = PointerGetDatum(cstring_to_text_with_len(text, len));
01212 do_tup_output(tstate, values, isnull);
01213 pfree(DatumGetPointer(values[0]));
01214 text = eol;
01215 }
01216 }
01217
01218 void
01219 end_tup_output(TupOutputState *tstate)
01220 {
01221 (*tstate->dest->rShutdown) (tstate->dest);
01222
01223 ExecDropSingleTupleTableSlot(tstate->slot);
01224 pfree(tstate);
01225 }