|
1 | 1 | /*
|
2 |
| - * $PostgreSQL: pgsql/contrib/tablefunc/tablefunc.c,v 1.60 2009/06/11 14:48:52 momjian Exp $ |
| 2 | + * $PostgreSQL: pgsql/contrib/tablefunc/tablefunc.c,v 1.61 2009/12/29 17:40:59 heikki Exp $ |
3 | 3 | *
|
4 | 4 | *
|
5 | 5 | * tablefunc
|
@@ -567,14 +567,9 @@ crosstab(PG_FUNCTION_ARGS)
|
567 | 567 | {
|
568 | 568 | HeapTuple tuple;
|
569 | 569 |
|
570 |
| - /* build the tuple */ |
| 570 | + /* build the tuple and store it */ |
571 | 571 | tuple = BuildTupleFromCStrings(attinmeta, values);
|
572 |
| - |
573 |
| - /* switch to appropriate context while storing the tuple */ |
574 |
| - oldcontext = MemoryContextSwitchTo(per_query_ctx); |
575 | 572 | tuplestore_puttuple(tupstore, tuple);
|
576 |
| - MemoryContextSwitchTo(oldcontext); |
577 |
| - |
578 | 573 | heap_freetuple(tuple);
|
579 | 574 | }
|
580 | 575 |
|
@@ -807,7 +802,6 @@ get_crosstab_tuplestore(char *sql,
|
807 | 802 | HeapTuple tuple;
|
808 | 803 | int ret;
|
809 | 804 | int proc;
|
810 |
| - MemoryContext SPIcontext; |
811 | 805 |
|
812 | 806 | /* initialize our tuplestore (while still in query context!) */
|
813 | 807 | tupstore = tuplestore_begin_heap(randomAccess, false, work_mem);
|
@@ -907,10 +901,7 @@ get_crosstab_tuplestore(char *sql,
|
907 | 901 | /* rowid changed, flush the previous output row */
|
908 | 902 | tuple = BuildTupleFromCStrings(attinmeta, values);
|
909 | 903 |
|
910 |
| - /* switch to appropriate context while storing the tuple */ |
911 |
| - SPIcontext = MemoryContextSwitchTo(per_query_ctx); |
912 | 904 | tuplestore_puttuple(tupstore, tuple);
|
913 |
| - MemoryContextSwitchTo(SPIcontext); |
914 | 905 |
|
915 | 906 | for (j = 0; j < result_ncols; j++)
|
916 | 907 | xpfree(values[j]);
|
@@ -943,10 +934,7 @@ get_crosstab_tuplestore(char *sql,
|
943 | 934 | /* flush the last output row */
|
944 | 935 | tuple = BuildTupleFromCStrings(attinmeta, values);
|
945 | 936 |
|
946 |
| - /* switch to appropriate context while storing the tuple */ |
947 |
| - SPIcontext = MemoryContextSwitchTo(per_query_ctx); |
948 | 937 | tuplestore_puttuple(tupstore, tuple);
|
949 |
| - MemoryContextSwitchTo(SPIcontext); |
950 | 938 | }
|
951 | 939 |
|
952 | 940 | if (SPI_finish() != SPI_OK_FINISH)
|
@@ -1232,7 +1220,6 @@ build_tuplestore_recursively(char *key_fld,
|
1232 | 1220 | Tuplestorestate *tupstore)
|
1233 | 1221 | {
|
1234 | 1222 | TupleDesc tupdesc = attinmeta->tupdesc;
|
1235 |
| - MemoryContext oldcontext; |
1236 | 1223 | int ret;
|
1237 | 1224 | int proc;
|
1238 | 1225 | int serial_column;
|
@@ -1310,15 +1297,9 @@ build_tuplestore_recursively(char *key_fld,
|
1310 | 1297 | /* construct the tuple */
|
1311 | 1298 | tuple = BuildTupleFromCStrings(attinmeta, values);
|
1312 | 1299 |
|
1313 |
| - /* switch to long lived context while storing the tuple */ |
1314 |
| - oldcontext = MemoryContextSwitchTo(per_query_ctx); |
1315 |
| - |
1316 | 1300 | /* now store it */
|
1317 | 1301 | tuplestore_puttuple(tupstore, tuple);
|
1318 | 1302 |
|
1319 |
| - /* now reset the context */ |
1320 |
| - MemoryContextSwitchTo(oldcontext); |
1321 |
| - |
1322 | 1303 | /* increment level */
|
1323 | 1304 | level++;
|
1324 | 1305 | }
|
@@ -1404,15 +1385,9 @@ build_tuplestore_recursively(char *key_fld,
|
1404 | 1385 | xpfree(current_key);
|
1405 | 1386 | xpfree(current_key_parent);
|
1406 | 1387 |
|
1407 |
| - /* switch to long lived context while storing the tuple */ |
1408 |
| - oldcontext = MemoryContextSwitchTo(per_query_ctx); |
1409 |
| - |
1410 | 1388 | /* store the tuple for later use */
|
1411 | 1389 | tuplestore_puttuple(tupstore, tuple);
|
1412 | 1390 |
|
1413 |
| - /* now reset the context */ |
1414 |
| - MemoryContextSwitchTo(oldcontext); |
1415 |
| - |
1416 | 1391 | heap_freetuple(tuple);
|
1417 | 1392 |
|
1418 | 1393 | /* recurse using current_key_parent as the new start_with */
|
|
0 commit comments