fix some mistake of COPY query in case of replication mode
authorpengbo <pengbo@localhost.localdomain>
Fri, 9 Sep 2016 04:29:54 +0000 (13:29 +0900)
committerpengbo <pengbo@localhost.localdomain>
Fri, 9 Sep 2016 04:32:11 +0000 (13:32 +0900)
src/context/pool_query_context.c
src/protocol/pool_process_query.c

index 754cbd31c18a09465879028db1c569f2d19cf763..1962e911928467667773660eaea431fb04a1dc69 100644 (file)
@@ -1156,15 +1156,18 @@ static POOL_DEST send_to_where(Node *node, char *query)
                 */
                else if (IsA(node, CopyStmt))
                {
-                       if (((CopyStmt *)node)->is_from)
-                       {
-                               return POOL_PRIMARY;
-                       } 
-                       else 
+                       if (((CopyStmt *)node)->is_from)
                        {
-                               return (IsA(((CopyStmt *)node)->query, SelectStmt))?POOL_EITHER:POOL_PRIMARY;
-                       }
-
+                               return POOL_PRIMARY;
+                       }
+                       else
+                       {
+                               if (((CopyStmt *)node)->query) {
+                                       return (IsA(((CopyStmt *)node)->query, SelectStmt))?POOL_EITHER:POOL_PRIMARY;
+                               } else {
+                                       return POOL_EITHER;
+                               }
+                       }
                }
 
                /*
index 784165823a4a5c3fb35e5f69a1bdcb9cfd1534bc..5a7ba19836a4fa69c56760aba45ab7212429619c 100644 (file)
@@ -1179,8 +1179,28 @@ bool is_select_query(Node *node, char *sql)
        else if (IsA(node, CopyStmt))
        {
                CopyStmt *copy_stmt = (CopyStmt *)node;
-               return (copy_stmt->is_from == FALSE &&
-                               copy_stmt->filename == NULL);
+               
+               if (copy_stmt->is_from)
+               {
+                       return false;
+               }
+               else if (copy_stmt->filename == NULL )
+               {
+                       if (copy_stmt->query == NULL)
+                       {
+                               return true;
+                       }
+                       else if (copy_stmt->query  && IsA(copy_stmt->query, SelectStmt))
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               return false;
+                       }
+               } else {
+                       return false;
+               }
        }
        else if (IsA(node, ExplainStmt))
        {