OSDN Git Service

bug fix #2
authorTakashi Suzuki <suzuki.takashi@metrosystems.co.jp>
Thu, 16 Jan 2014 05:02:23 +0000 (14:02 +0900)
committerTakashi Suzuki <suzuki.takashi@metrosystems.co.jp>
Thu, 16 Jan 2014 05:02:23 +0000 (14:02 +0900)
件数補正のときに、全ての結合パスにおいて部分集合となってしまい、他
のRowsヒント句適用後に見積もり件数を再計算してしまった。。

理由
  Rowsヒント句に存在しないテーブル組合せを指定すると、pg_hint_plan
  内部で空のテーブル集合として扱っていたため。

make_join_rel.c
pg_hint_plan.c

index d3a90f4..7d17183 100644 (file)
@@ -117,6 +117,13 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
        {
                rows_hint = current_hint->rows_hints[i];
 
+               /*
+                * This Rows hint specifies aliasname is error, or does not exist in
+                * query.
+                */
+               if (!rows_hint->joinrelids ||
+                       rows_hint->base.state == HINT_STATE_ERROR)
+                       continue;
                if (bms_equal(joinrelids, rows_hint->joinrelids))
                {
                        /*
index aebc709..5b487bc 100644 (file)
@@ -3210,9 +3210,15 @@ create_bms_of_relids(Hint *base, PlannerInfo *root, List *initial_rels,
                if (relid == -1)
                        base->state = HINT_STATE_ERROR;
 
+               /*
+                * the aliasname is not found(relid == 0) or same aliasname was used
+                * multiple times in a query(relid == -1)
+                */
                if (relid <= 0)
+               {
+                       relids = NULL;
                        break;
-
+               }
                if (bms_is_member(relid, relids))
                {
                        hint_ereport(base->hint_str,
@@ -3279,9 +3285,6 @@ transform_join_hints(HintState *hstate, PlannerInfo *root, int nbaserel,
 
                hint->joinrelids = create_bms_of_relids(&(hint->base), root,
                                                                         initial_rels, hint->nrels, hint->relnames);
-
-               if (hint->joinrelids == NULL || hint->base.state == HINT_STATE_ERROR)
-                       continue;
        }
 
        /* Do nothing if no Leading hint was supplied. */