distinguish unknown and zero number of affected rows
authorTeodor Sigaev <teodor@sigaev.ru>
Mon, 29 Aug 2016 14:19:14 +0000 (17:19 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Mon, 29 Aug 2016 14:19:14 +0000 (17:19 +0300)
online_analyze.c

index c4c2691..4c3e044 100644 (file)
@@ -318,7 +318,7 @@ makeRangeVarFromOid(Oid relOid)
 #endif
 
 static void
-makeAnalyze(Oid relOid, CmdType operation, uint32 naffected)
+makeAnalyze(Oid relOid, CmdType operation, int32 naffected)
 {
        PgStat_StatTabEntry             *tabentry;
        TimestampTz                     now = GetCurrentTimestamp();
@@ -326,6 +326,13 @@ makeAnalyze(Oid relOid, CmdType operation, uint32 naffected)
        if (relOid == InvalidOid)
                return;
 
+       if (naffected == 0)
+               /* return if there is not changes */
+               return;
+       else if (naffected < 0)
+               /* number if affected rows is unknown */
+               naffected = 0;
+
        if (get_rel_relkind(relOid) != RELKIND_RELATION)
                return;
 
@@ -479,7 +486,7 @@ extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc);
 void
 onlineAnalyzeHooker(QueryDesc *queryDesc)
 {
-       uint32  naffected = 0;
+       uint32  naffected = -1;
 
        if (queryDesc->estate)
                naffected = queryDesc->estate->es_processed;
@@ -558,7 +565,7 @@ onlineAnalyzeHookerUtility(Node *parsetree, const char *queryString,
        if (tblname) {
                Oid     tblOid = RangeVarGetRelid(tblname, NoLock, true);
 
-               makeAnalyze(tblOid, CMD_INSERT, 0); 
+               makeAnalyze(tblOid, CMD_INSERT, -1); 
        }
 }
 #endif