int deadlock_detected = 0;
int active_sql_transaction_error = 0;
+ POOL_MEMORY_POOL *old_context = NULL;
+ Portal *portal;
+
force_replication = 0;
if (query == NULL) /* need to read query from frontend? */
{
if (MASTER_SLAVE && TSTATE(backend) != 'E')
force_replication = 1;
- if (frontend)
+ /*
+ * Before we do followings only when frontend == NULL,
+ * which was wrong since if, for example, reset_query_list
+ * contains "DISCARD ALL", then it does not register
+ * pending function and it causes trying to DEALLOCATE non
+ * existing prepared statment(2009/4/3 Tatsuo).
+ */
+ if (IsA(node, PrepareStmt))
{
- POOL_MEMORY_POOL *old_context = NULL;
- Portal *portal;
-
- if (IsA(node, PrepareStmt))
+ pending_function = add_prepared_list;
+ portal = create_portal();
+ if (portal == NULL)
{
- pending_function = add_prepared_list;
- portal = create_portal();
- if (portal == NULL)
- {
- pool_error("SimpleQuery: create_portal() failed");
- return POOL_END;
- }
+ pool_error("SimpleQuery: create_portal() failed");
+ return POOL_END;
+ }
- /* switch memory context */
- old_context = pool_memory;
- pool_memory = portal->prepare_ctxt;
+ /* switch memory context */
+ old_context = pool_memory;
+ pool_memory = portal->prepare_ctxt;
- portal->portal_name = NULL;
- portal->stmt = copyObject(node);
- portal->sql_string = NULL;
- pending_prepared_portal = portal;
- }
- else if (IsA(node, DeallocateStmt))
+ portal->portal_name = NULL;
+ portal->stmt = copyObject(node);
+ portal->sql_string = NULL;
+ pending_prepared_portal = portal;
+ }
+ else if (IsA(node, DeallocateStmt))
+ {
+ pending_function = del_prepared_list;
+ portal = create_portal();
+ if (portal == NULL)
{
- pending_function = del_prepared_list;
- portal = create_portal();
- if (portal == NULL)
- {
- pool_error("SimpleQuery: create_portal() failed");
- return POOL_END;
- }
+ pool_error("SimpleQuery: create_portal() failed");
+ return POOL_END;
+ }
- /* switch memory context */
- old_context = pool_memory;
- pool_memory = portal->prepare_ctxt;
+ /* switch memory context */
+ old_context = pool_memory;
+ pool_memory = portal->prepare_ctxt;
- portal->portal_name = NULL;
- portal->stmt = copyObject(node);
- portal->sql_string = NULL;
- pending_prepared_portal = portal;
- }
- else if (IsA(node, DiscardStmt))
+ portal->portal_name = NULL;
+ portal->stmt = copyObject(node);
+ portal->sql_string = NULL;
+ pending_prepared_portal = portal;
+ }
+ else if (IsA(node, DiscardStmt))
+ {
+ DiscardStmt *stmt = (DiscardStmt *)node;
+ if (stmt->target == DISCARD_ALL || stmt->target == DISCARD_PLANS)
{
- DiscardStmt *stmt = (DiscardStmt *)node;
- if (stmt->target == DISCARD_ALL || stmt->target == DISCARD_PLANS)
- {
- pending_function = delete_all_prepared_list;
- pending_prepared_portal = NULL;
- }
+ pending_function = delete_all_prepared_list;
+ pending_prepared_portal = NULL;
}
-
- /* switch old memory context */
- if (old_context)
- pool_memory = old_context;
}
+
+ /* switch old memory context */
+ if (old_context)
+ pool_memory = old_context;
+
+ /* end of wrong if (see 2009/4/3 comment above) */
}
if (frontend && IsA(node, ExecuteStmt))