OSDN Git Service

Fix text plan representation for sort keys
authorKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Thu, 25 Aug 2016 02:01:05 +0000 (11:01 +0900)
committerKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Fri, 26 Aug 2016 04:37:05 +0000 (13:37 +0900)
Sort keys are in a list but read as a simple string. As the result
only the last of the list is shown in a text representation. This
commit fixes it.  This patch adds new setter macro LIST_SETTER for
this purpose and Output: is also changed to make use of the macro.

pgsp_json_text.c
pgsp_json_text.h

index 7d7785b..6389dcc 100644 (file)
@@ -52,19 +52,6 @@ SETTERDECL(node_type)
        }
 }
 
-SETTERDECL(output)
-{
-       if(!vals->output)
-       {
-               vals->output = makeStringInfo();
-               appendStringInfoString(vals->output, val);
-       }
-       else
-       {
-               appendStringInfoString(vals->output, ", ");
-               appendStringInfoString(vals->output, val);
-       }
-}
 SETTERDECL(strategy)
 {
        word_table *p;
@@ -98,11 +85,12 @@ CONVERSION_SETTER(scan_dir, conv_scandir);
 SQLQUOTE_SETTER(obj_name);
 SQLQUOTE_SETTER(alias);
 SQLQUOTE_SETTER(schema_name);
+LIST_SETTER(output);
 DEFAULT_SETTER(merge_cond);
 CONVERSION_SETTER(join_type, conv_jointype);
 CONVERSION_SETTER(setopcommand, conv_setsetopcommand);
 CONVERSION_SETTER(sort_method, conv_sortmethod);
-DEFAULT_SETTER(sort_key);
+LIST_SETTER(sort_key);
 SQLQUOTE_SETTER(index_name);
 DEFAULT_SETTER(startup_cost);
 DEFAULT_SETTER(total_cost);
@@ -214,6 +202,19 @@ print_prop_if_exists(StringInfo s, char *prepstr,
 }
 
 static void
+print_propstr_if_exists(StringInfo s, char *prepstr,
+                                               StringInfo prop, int level, int exind)
+{
+       if (prop && prop->data[0])
+       {
+               appendStringInfoString(s, "\n");
+               appendStringInfoSpaces(s, TEXT_INDENT_DETAILS(level, exind));
+               appendStringInfoString(s, prepstr);
+               appendStringInfoString(s, prop->data);
+       }
+}
+
+static void
 print_prop_if_nz(StringInfo s, char *prepstr,
                                 const char *prop, int level, int exind)
 {
@@ -339,20 +340,14 @@ print_current_node(pgspParserContext *ctx)
                appendStringInfoString(s, ")");
        }
 
-       if (v->output)
-       {
-               appendStringInfoString(s, "\n");
-               appendStringInfoSpaces(s, TEXT_INDENT_DETAILS(level, exind));
-               appendStringInfoString(s, "Output: ");
-               appendStringInfoString(s, v->output->data);
-       }
+       print_propstr_if_exists(s, "Output: ", v->output, level, exind);
        print_prop_if_exists(s, "Merge Cond: ", v->merge_cond, level, exind);
        print_prop_if_exists(s, "Hash Cond: " , v->hash_cond, level, exind);
        print_prop_if_exists(s, "Tid Cond: " , v->tid_cond, level, exind);
        print_prop_if_exists(s, "Join Filter: " , v->join_filter, level, exind);
        print_prop_if_exists(s, "Index Cond: " , v->index_cond, level, exind);
        print_prop_if_exists(s, "Recheck Cond: ", v->recheck_cond, level, exind);
-       print_prop_if_exists(s, "Sort Key: ", v->sort_key, level, exind);
+       print_propstr_if_exists(s, "Sort Key: ", v->sort_key, level, exind);
 
        if (HASSTRING(v->sort_method))
        {
index 4643cef..4aa1518 100644 (file)
@@ -29,7 +29,7 @@ typedef struct
        StringInfo output;
        const char *func_call;
        const char *sort_method;
-       const char *sort_key;
+       StringInfo sort_key;
        const char *index_cond;
        const char *merge_cond;
        const char *hash_cond;
@@ -87,6 +87,20 @@ typedef struct
 #define SQLQUOTE_SETTER(name) \
        SETTERDECL(name) { vals->name = quote_identifier(val);}
 
+#define LIST_SETTER(name) \
+       SETTERDECL(name) { \
+               if (!vals->name)\
+               { \
+                       vals->name = makeStringInfo(); \
+                       appendStringInfoString(vals->name, val); \
+               } \
+               else \
+               { \
+                       appendStringInfoString(vals->name, ", "); \
+                       appendStringInfoString(vals->name, val); \
+               } \
+       }\
+
 #define CONVERSION_SETTER(name, converter) \
        SETTERDECL(name) { vals->name = converter(val, PGSP_JSON_TEXTIZE);}