Re: Funny representation in pg_stat_statements.query.

Поиск
Список
Период
Сортировка
От Kyotaro HORIGUCHI
Тема Re: Funny representation in pg_stat_statements.query.
Дата
Msg-id 20140121.173016.223496951.horiguchi.kyotaro@lab.ntt.co.jp
обсуждение исходный текст
Ответ на Re: Funny representation in pg_stat_statements.query.  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
Ответы Re: Funny representation in pg_stat_statements.query.  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Funny representation in pg_stat_statements.query.  (Peter Geoghegan <pg@heroku.com>)
Re: Funny representation in pg_stat_statements.query.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello, I found it would be reasonably fixed by small
modifications.

>  - CURRENT_TIME and the like are parsed into the nodes directly
>    represents the node specs in gram.y
<blah, blah>
> Since this becomes more than a simple bug fix, I think it is too
> late for 9.4 now. I'll work on this in the longer term.

The fundamental cause of this issue is Const node which conveys
the location of other than constant tokens. Any other nodes, for
instance TypeCasts, are safe.

So this is fixed by quite simple way like following getting rid
of the referred difficulties of keeping the code sane and total
loss of token locations. (white spaces are collapsed for readability)

| --- a/src/backend/parser/gram.y
| +++ b/src/backend/parser/gram.y
| @@ -11355,8 +11355,8 @@ func_expr_common_subexpr:
|       * to rely on it.)
|       */
|      Node *n;
| -    n = makeStringConstCast("now", @1, SystemTypeName("text"));
| -    $$ = makeTypeCast(n, SystemTypeName("date"), -1);
| +    n = makeStringConstCast("now", -1, SystemTypeName("text"));
| +    $$ = makeTypeCast(n, SystemTypeName("date"), @1);

Any suggestions? Attached is the complete patch.

As of 9.4dev, transformTypeCast passes the locations retrieved
from the source TypeCast node itself or its TypeName subnode to
the newly created CoerceViaIO node but leaves that of the inner
expressions (the "now", I mean) as it is, so I think this fits to
what transformTypeCast does more than before. The query tree
after the transformation sees like follows. I think this is
preferable to that -1 to CoerceViaIO and 7 to Const.

... {   type = TargetEtnry   expr = {     type = CoerceViaIO, location = 7,     arg = {       type = Const, location =
-1    }   } }
 

In addition, the location stored in StringConstCast seems
currently not having no route to users' sight, even any step out
the node - in short 'useless'. And yet the location of
CoerceViaIO is also not used...

|    | CURRENT_DATE
..
|-         n = makeStringConstCast("now", @1, SystemTypeName("text")
|+         n = makeStringConstCast("nowe", @1, SystemTypeName("text")

yields only this, including logs.

| =# select CURRENT_DATE;
| ERROR:  invalid input syntax for type date: "nowe"


regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 12a6beb..a14a381 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11399,8 +11399,8 @@ func_expr_common_subexpr:                     * to rely on it.)                     */
         Node *n;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
-                    $$ = makeTypeCast(n, SystemTypeName("date"), -1);
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));
+                    $$ = makeTypeCast(n, SystemTypeName("date"), @1);                }            | CURRENT_TIME
        {
 
@@ -11409,8 +11409,8 @@ func_expr_common_subexpr:                     * See comments for CURRENT_DATE.
  */                    Node *n;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
-                    $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));
+                    $$ = makeTypeCast(n, SystemTypeName("timetz"), @1);                }            | CURRENT_TIME '('
Iconst')'                {
 
@@ -11420,10 +11420,10 @@ func_expr_common_subexpr:                     */                    Node *n;
 TypeName *d;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));                    d =
SystemTypeName("timetz");                   d->typmods = list_make1(makeIntConst($3, @3));
 
-                    $$ = makeTypeCast(n, d, -1);
+                    $$ = makeTypeCast(n, d, @1);                }            | CURRENT_TIMESTAMP                {
@@ -11441,10 +11441,10 @@ func_expr_common_subexpr:                     */                    Node *n;
 TypeName *d;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));                    d =
SystemTypeName("timestamptz");                   d->typmods = list_make1(makeIntConst($3, @3));
 
-                    $$ = makeTypeCast(n, d, -1);
+                    $$ = makeTypeCast(n, d, @1);                }            | LOCALTIME                {
@@ -11453,8 +11453,8 @@ func_expr_common_subexpr:                     * See comments for CURRENT_DATE.
  */                    Node *n;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
-                    $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));
+                    $$ = makeTypeCast((Node *)n, SystemTypeName("time"), @1);                }            | LOCALTIME
'('Iconst ')'                {
 
@@ -11464,10 +11464,10 @@ func_expr_common_subexpr:                     */                    Node *n;
 TypeName *d;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));                    d =
SystemTypeName("time");                   d->typmods = list_make1(makeIntConst($3, @3));
 
-                    $$ = makeTypeCast((Node *)n, d, -1);
+                    $$ = makeTypeCast((Node *)n, d, @1);                }            | LOCALTIMESTAMP
{
@@ -11476,8 +11476,8 @@ func_expr_common_subexpr:                     * See comments for CURRENT_DATE.
  */                    Node *n;
 
-                    n = makeStringConstCast("now", @1, SystemTypeName("text"));
-                    $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
+                    n = makeStringConstCast("now", -1, SystemTypeName("text"));
+                    $$ = makeTypeCast(n, SystemTypeName("timestamp"), @1);                }            |
LOCALTIMESTAMP'(' Iconst ')'                { 

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Jeevan Chalke
Дата:
Сообщение: Re: patch: option --if-exists for pg_dump
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: proposal: hide application_name from other users