|
26 | 26 | *
|
27 | 27 | *
|
28 | 28 | * IDENTIFICATION
|
29 |
| - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.249 2005/05/22 22:30:19 tgl Exp $ |
| 29 | + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.250 2005/06/20 18:37:01 tgl Exp $ |
30 | 30 | *
|
31 | 31 | *-------------------------------------------------------------------------
|
32 | 32 | */
|
33 | 33 | #include"postgres.h"
|
34 | 34 |
|
35 | 35 | #include"access/heapam.h"
|
| 36 | +#include"access/xlog.h" |
36 | 37 | #include"catalog/heap.h"
|
37 | 38 | #include"catalog/namespace.h"
|
38 | 39 | #include"commands/tablecmds.h"
|
|
44 | 45 | #include"optimizer/clauses.h"
|
45 | 46 | #include"optimizer/var.h"
|
46 | 47 | #include"parser/parsetree.h"
|
| 48 | +#include"storage/smgr.h" |
47 | 49 | #include"utils/acl.h"
|
48 | 50 | #include"utils/guc.h"
|
49 | 51 | #include"utils/lsyscache.h"
|
@@ -784,6 +786,20 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
|
784 | 786 | * And open the constructed table for writing.
|
785 | 787 | */
|
786 | 788 | intoRelationDesc=heap_open(intoRelationId,AccessExclusiveLock);
|
| 789 | + |
| 790 | +/* use_wal off requires rd_targblock be initially invalid */ |
| 791 | +Assert(intoRelationDesc->rd_targblock==InvalidBlockNumber); |
| 792 | + |
| 793 | +/* |
| 794 | + * We can skip WAL-logging the insertions, unless PITR is in use. |
| 795 | + * |
| 796 | + * Note that for a non-temp INTO table, this is safe only because |
| 797 | + * we know that the catalog changes above will have been WAL-logged, |
| 798 | + * and so RecordTransactionCommit will think it needs to WAL-log the |
| 799 | + * eventual transaction commit. Else the commit might be lost, even |
| 800 | + * though all the data is safely fsync'd ... |
| 801 | + */ |
| 802 | +estate->es_into_relation_use_wal=XLogArchivingActive(); |
787 | 803 | }
|
788 | 804 |
|
789 | 805 | estate->es_into_relation_descriptor=intoRelationDesc;
|
@@ -979,7 +995,22 @@ ExecEndPlan(PlanState *planstate, EState *estate)
|
979 | 995 | * close the "into" relation if necessary, again keeping lock
|
980 | 996 | */
|
981 | 997 | if (estate->es_into_relation_descriptor!=NULL)
|
| 998 | +{ |
| 999 | +/* |
| 1000 | + * If we skipped using WAL, and it's not a temp relation, |
| 1001 | + * we must force the relation down to disk before it's |
| 1002 | + * safe to commit the transaction. This requires forcing |
| 1003 | + * out any dirty buffers and then doing a forced fsync. |
| 1004 | + */ |
| 1005 | +if (!estate->es_into_relation_use_wal&& |
| 1006 | +!estate->es_into_relation_descriptor->rd_istemp) |
| 1007 | +{ |
| 1008 | +FlushRelationBuffers(estate->es_into_relation_descriptor); |
| 1009 | +smgrimmedsync(estate->es_into_relation_descriptor->rd_smgr); |
| 1010 | +} |
| 1011 | + |
982 | 1012 | heap_close(estate->es_into_relation_descriptor,NoLock);
|
| 1013 | + } |
983 | 1014 |
|
984 | 1015 | /*
|
985 | 1016 | * close any relations selected FOR UPDATE/FOR SHARE, again keeping locks
|
@@ -1307,7 +1338,9 @@ ExecSelect(TupleTableSlot *slot,
|
1307 | 1338 |
|
1308 | 1339 | tuple=ExecCopySlotTuple(slot);
|
1309 | 1340 | heap_insert(estate->es_into_relation_descriptor,tuple,
|
1310 |
| -estate->es_snapshot->curcid); |
| 1341 | +estate->es_snapshot->curcid, |
| 1342 | +estate->es_into_relation_use_wal, |
| 1343 | +false);/* never any point in using FSM */ |
1311 | 1344 | /* we know there are no indexes to update */
|
1312 | 1345 | heap_freetuple(tuple);
|
1313 | 1346 | IncrAppended();
|
@@ -1386,7 +1419,8 @@ ExecInsert(TupleTableSlot *slot,
|
1386 | 1419 | * insert the tuple
|
1387 | 1420 | */
|
1388 | 1421 | newId=heap_insert(resultRelationDesc,tuple,
|
1389 |
| -estate->es_snapshot->curcid); |
| 1422 | +estate->es_snapshot->curcid, |
| 1423 | +true, true); |
1390 | 1424 |
|
1391 | 1425 | IncrAppended();
|
1392 | 1426 | (estate->es_processed)++;
|
@@ -2089,6 +2123,7 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq)
|
2089 | 2123 | epqstate->es_result_relation_info=estate->es_result_relation_info;
|
2090 | 2124 | epqstate->es_junkFilter=estate->es_junkFilter;
|
2091 | 2125 | epqstate->es_into_relation_descriptor=estate->es_into_relation_descriptor;
|
| 2126 | +epqstate->es_into_relation_use_wal=estate->es_into_relation_use_wal; |
2092 | 2127 | epqstate->es_param_list_info=estate->es_param_list_info;
|
2093 | 2128 | if (estate->es_topPlan->nParamExec>0)
|
2094 | 2129 | epqstate->es_param_exec_vals= (ParamExecData*)
|
|