Do not miss relkind check
authorTeodor Sigaev <teodor@sigaev.ru>
Tue, 18 Oct 2016 07:52:20 +0000 (10:52 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Tue, 18 Oct 2016 07:52:20 +0000 (10:52 +0300)
online_analyze.c

index 0d85df6..25a1ecf 100644 (file)
@@ -323,6 +323,8 @@ makeAnalyze(Oid relOid, CmdType operation, int32 naffected)
 {
        PgStat_StatTabEntry             *tabentry;
        TimestampTz                             now = GetCurrentTimestamp();
+       Relation                                rel;
+       OnlineAnalyzeTableType  reltype;
 
        if (relOid == InvalidOid)
                return;
@@ -334,6 +336,23 @@ makeAnalyze(Oid relOid, CmdType operation, int32 naffected)
                /* number if affected rows is unknown */
                naffected = 0;
 
+       rel = RelationIdGetRelation(relOid);
+       if (rel->rd_rel->relkind != RELKIND_RELATION)
+       {
+               RelationClose(rel);
+               return;
+       }
+
+       reltype =
+#if PG_VERSION_NUM >= 90100
+               (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+#else
+               (rel->rd_istemp || rel->rd_islocaltemp)
+#endif
+                       ? OATT_TEMPORARY : OATT_PERSISTENT;
+
+       RelationClose(rel);
+
        /*
         * includeTables overwrites excludeTables
         */
@@ -353,39 +372,17 @@ makeAnalyze(Oid relOid, CmdType operation, int32 naffected)
                case OATT_TEMPORARY:
                case OATT_PERSISTENT:
                default:
+                       /*
+                        * skip analyze if relation's type doesn't not match
+                        * online_analyze_table_type
+                        */
+                       if ((online_analyze_table_type & reltype) == 0 ||
+                               matchOid(&excludeTables, relOid) == true)
                        {
-                               Relation                                rel;
-                               OnlineAnalyzeTableType  reltype;
-
-                               rel = RelationIdGetRelation(relOid);
-
-                               if (rel->rd_rel->relkind != RELKIND_RELATION)
-                               {
-                                       RelationClose(rel);
+                               if (matchOid(&includeTables, relOid) == false)
                                        return;
-                               }
-
-                               reltype =
-#if PG_VERSION_NUM >= 90100
-                                       (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
-#else
-                                       (rel->rd_istemp || rel->rd_islocaltemp)
-#endif
-                                               ? OATT_TEMPORARY : OATT_PERSISTENT;
-                               RelationClose(rel);
-
-                               /*
-                                * skip analyze if relation's type doesn't not match
-                                * online_analyze_table_type
-                                */
-                               if ((online_analyze_table_type & reltype) == 0 ||
-                                       matchOid(&excludeTables, relOid) == true)
-                               {
-                                       if (matchOid(&includeTables, relOid) == false)
-                                               return;
-                               }
-                               break;
                        }
+                       break;
        }
 
        tabentry = pgstat_fetch_stat_tabentry(relOid);