Make some fixes to handle temp objects.
authorPavan Deolasee <[email protected]>
Tue, 16 Jul 2019 03:56:07 +0000 (09:26 +0530)
committerPavan Deolasee <[email protected]>
Tue, 16 Jul 2019 03:56:07 +0000 (09:26 +0530)
Fix the broken handling for LOCK <temp_table> and some other misc fixes.

src/backend/access/transam/xact.c
src/backend/parser/gram.y
src/backend/tcop/utility.c

index d091f9fcf0b791db4d72d0ba5564e35958bd2d4d..50daccaca48d26ef3dc07bb9635b3f4b7a021dac 100644 (file)
@@ -2881,6 +2881,18 @@ PrepareTransaction(void)
        if (IS_PGXC_DATANODE || !IsConnFromCoord())
        {
                char            *nodestring;
+
+               /*
+                * Before we prepare remote nodes, check if we have accessed any temp
+                * tables and bail out. We do this extra check here to avoid any
+                * in-doubt prepared transactions on remote node. See below to know
+                * more about why prepare transactions are blocked.
+                */
+               if ((MyXactFlags & XACT_FLAGS_ACCESSEDTEMPREL))
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                        errmsg("cannot PREPARE a transaction that has operated on temporary tables")));
+
                if (saveNodeString)
                {
                        pfree(saveNodeString);
index c3dc5de248653e555db0f74c8705a8268096ac9f..21760cf57b957a02a6641b4581b7f23bc34b6432 100644 (file)
@@ -10958,6 +10958,11 @@ ExecuteStmt: EXECUTE name execute_param_clause
                                        ctas->if_not_exists = true;
                                        /* cram additional flags into the IntoClause */
                                        $7->rel->relpersistence = $2;
+#ifdef PGXC
+                                       ereport(ERROR,
+                                                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                        errmsg("CREATE TABLE IF NOT EXISTS AS EXECUTE not yet supported")));
+#endif
                                        $7->skipData = !($12);
                                        $$ = (Node *) ctas;
                                }
index 491e3bdf291a8a726ceadfd42706840bd4a82729..fae5719adeef87deb5ddb6f45c81a3f2dd04f172 100644 (file)
@@ -994,7 +994,6 @@ ProcessUtilityPost(PlannedStmt *pstmt,
                case T_AlterRoleSetStmt:
                case T_DropRoleStmt:
                case T_ReassignOwnedStmt:
-               case T_LockStmt:
                case T_AlterOwnerStmt:
                case T_AlterDomainStmt:
                case T_DefineStmt:
@@ -1025,6 +1024,38 @@ ProcessUtilityPost(PlannedStmt *pstmt,
                        exec_type = EXEC_ON_ALL_NODES;
                        break;
 
+               case T_LockStmt:
+                       if (IS_PGXC_LOCAL_COORDINATOR)
+                       {
+                               ListCell        *cell;
+                               LockStmt        *stmt = (LockStmt *) parsetree;
+                               bool            found_temp = false;
+                               bool            found_regular = false;
+
+                               foreach(cell, stmt->relations)
+                               {
+                                       Oid relid;
+                                       RangeVar *rel = (RangeVar *) lfirst(cell);
+
+                                       relid = RangeVarGetRelid(rel, NoLock, false);
+                                       if (IsTempTable(relid))
+                                               is_temp = found_temp = true;
+                                       else
+                                               found_regular = true;
+                               }
+
+                               if (found_regular && found_temp)
+                                       ereport(ERROR,
+                                                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                        errmsg("Cannot LOCK temp and non-temp tables "
+                                                                "in a single statement")));
+                               if (is_temp)
+                                       exec_type = EXEC_ON_DATANODES;
+                               else
+                                       exec_type = EXEC_ON_ALL_NODES;
+                       }
+                       break;
+
                case T_TruncateStmt:
                        /*
                         * Check details of the object being truncated.