OSDN Git Service

Fix the wrong measure for the change in ExplainState.
authorKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Tue, 10 Feb 2015 00:37:10 +0000 (09:37 +0900)
committerKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Fri, 3 Apr 2015 07:40:37 +0000 (16:40 +0900)
The fix made in the commit 6819c84350ea599988440c5c07becfe56c71723a is
not appropriate according to its objective. The correct fix for the
change is translating es->extra as "List *grouping_stack" in the
versions 9.3.6, 9.4.1 and their successors. This secure the binary
comaptibility throughout minor PG versions.

pgsp_explain.c

index fa986b8..6bdc6ed 100644 (file)
@@ -22,9 +22,17 @@ static void pgspExplainProperty(const char *qlabel, const char *value, bool nume
                                                        ExplainState *es);
 static void pgspExplainJSONLineEnding(ExplainState *es);
 
-/* ExplainState is modified at 9.4.1 and 9.3.6  */
-#if PG_VERSION_NUM >= 90401 || (PG_VERSION_NUM >= 90306 && PG_VERSION_NUM < 90400)
-#define GROUPING_STACK(es) ((es)->extra->groupingstack)
+/*
+ * ExplainState is modified at 9.4.1 and 9.3.6. But the change is for
+ * internal use and to avoid binary-incompatibility not changing the
+ * size of ExplainState. So we can use ExplainState->extra as if it
+ * were grouping_stack safely and should do so. Using ->extra as List*
+ * discards the memory for ExplainStateExtra but it is not a problem
+ * since it is allocated by palloc.
+ */
+#if (PG_VERSION_NUM >= 90401 && PG_VERSION_NUM < 90500) || \
+       (PG_VERSION_NUM >= 90306 && PG_VERSION_NUM < 90400)
+#define GROUPING_STACK(es) (*((List **)(&(es)->extra)))
 #else
 #define GROUPING_STACK(es) ((es)->grouping_stack)
 #endif