Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17f8ffa

Browse files
committed
Fix REFRESH MATERIALIZED VIEW to report activity to the stats collector.
The non-concurrent code path for REFRESH MATERIALIZED VIEW failed toreport its updates to the stats collector. This is bad since it meansauto-analyze doesn't know there's any work to be done. Adjust it toreport the refresh as a table truncate followed by insertion of anappropriate number of rows.Since a matview could contain more than INT_MAX rows, change thesignature of pgstat_count_heap_insert() to accept an int64 rowcount.(The accumulator it's adding into is already int64, but existingcallers could not insert more than a small number of rows at once,so the argument had been declared just "int n".)This is surely a bug fix, but changing pgstat_count_heap_insert()'s APIseems too risky for the back branches. Given the lack of previouscomplaints, I'm not sure it's a big enough problem to justify a klugesolution that would avoid that. So, no back-patch, at least for now.Jim Mlodgenski, adjusted a bit by meDiscussion:https://postgr.es/m/CAB_5SRchSz7-WmdO5szdiknG8Oj_GGqJytrk1KRd11yhcMs1KQ@mail.gmail.com
1 parent27f1f58 commit17f8ffa

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

‎src/backend/commands/matview.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include"executor/spi.h"
3131
#include"miscadmin.h"
3232
#include"parser/parse_relation.h"
33+
#include"pgstat.h"
3334
#include"rewrite/rewriteHandler.h"
3435
#include"storage/lmgr.h"
3536
#include"storage/smgr.h"
@@ -59,7 +60,7 @@ static void transientrel_startup(DestReceiver *self, int operation, TupleDesc ty
5960
staticbooltransientrel_receive(TupleTableSlot*slot,DestReceiver*self);
6061
staticvoidtransientrel_shutdown(DestReceiver*self);
6162
staticvoidtransientrel_destroy(DestReceiver*self);
62-
staticvoidrefresh_matview_datafill(DestReceiver*dest,Query*query,
63+
staticuint64refresh_matview_datafill(DestReceiver*dest,Query*query,
6364
constchar*queryString);
6465

6566
staticchar*make_temptable_name_n(char*tempname,intn);
@@ -145,6 +146,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
145146
Oidrelowner;
146147
OidOIDNewHeap;
147148
DestReceiver*dest;
149+
uint64processed=0;
148150
boolconcurrent;
149151
LOCKMODElockmode;
150152
charrelpersistence;
@@ -322,7 +324,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
322324

323325
/* Generate the data, if wanted. */
324326
if (!stmt->skipData)
325-
refresh_matview_datafill(dest,dataQuery,queryString);
327+
processed=refresh_matview_datafill(dest,dataQuery,queryString);
326328

327329
heap_close(matviewRel,NoLock);
328330

@@ -345,8 +347,20 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
345347
Assert(matview_maintenance_depth==old_depth);
346348
}
347349
else
350+
{
348351
refresh_by_heap_swap(matviewOid,OIDNewHeap,relpersistence);
349352

353+
/*
354+
* Inform stats collector about our activity: basically, we truncated
355+
* the matview and inserted some new data. (The concurrent code path
356+
* above doesn't need to worry about this because the inserts and
357+
* deletes it issues get counted by lower-level code.)
358+
*/
359+
pgstat_count_truncate(matviewRel);
360+
if (!stmt->skipData)
361+
pgstat_count_heap_insert(matviewRel,processed);
362+
}
363+
350364
/* Roll back any GUC changes */
351365
AtEOXact_GUC(false,save_nestlevel);
352366

@@ -360,15 +374,21 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
360374

361375
/*
362376
* refresh_matview_datafill
377+
*
378+
* Execute the given query, sending result rows to "dest" (which will
379+
* insert them into the target matview).
380+
*
381+
* Returns number of rows inserted.
363382
*/
364-
staticvoid
383+
staticuint64
365384
refresh_matview_datafill(DestReceiver*dest,Query*query,
366385
constchar*queryString)
367386
{
368387
List*rewritten;
369388
PlannedStmt*plan;
370389
QueryDesc*queryDesc;
371390
Query*copied_query;
391+
uint64processed;
372392

373393
/* Lock and rewrite, using a copy to preserve the original query. */
374394
copied_query=copyObject(query);
@@ -406,13 +426,17 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
406426
/* run the plan */
407427
ExecutorRun(queryDesc,ForwardScanDirection,0L);
408428

429+
processed=queryDesc->estate->es_processed;
430+
409431
/* and clean up */
410432
ExecutorFinish(queryDesc);
411433
ExecutorEnd(queryDesc);
412434

413435
FreeQueryDesc(queryDesc);
414436

415437
PopActiveSnapshot();
438+
439+
returnprocessed;
416440
}
417441

418442
DestReceiver*

‎src/backend/postmaster/pgstat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
18031803
* pgstat_count_heap_insert - count a tuple insertion of n tuples
18041804
*/
18051805
void
1806-
pgstat_count_heap_insert(Relationrel,intn)
1806+
pgstat_count_heap_insert(Relationrel,PgStat_Countern)
18071807
{
18081808
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
18091809

‎src/include/pgstat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ pgstat_report_wait_end(void)
12561256
#definepgstat_count_buffer_write_time(n)\
12571257
(pgStatBlockWriteTime += (n))
12581258

1259-
externvoidpgstat_count_heap_insert(Relationrel,intn);
1259+
externvoidpgstat_count_heap_insert(Relationrel,PgStat_Countern);
12601260
externvoidpgstat_count_heap_update(Relationrel,boolhot);
12611261
externvoidpgstat_count_heap_delete(Relationrel);
12621262
externvoidpgstat_count_truncate(Relationrel);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp