mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
For multi-table ANALYZE, use per-table transactions when possible
(ie, when not inside a transaction block), so that we can avoid holding locks longer than necessary. Per trouble report from Philip Warner.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.166 2004/05/21 05:07:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.167 2004/05/22 23:14:37 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@ -1417,7 +1417,7 @@ PreventTransactionChain(void *stmtNode, const char *stmtType)
|
||||
errmsg("%s cannot be executed from a function", stmtType)));
|
||||
/* If we got past IsTransactionBlock test, should be in default state */
|
||||
if (CurrentTransactionState->blockState != TBLOCK_DEFAULT &&
|
||||
CurrentTransactionState->blockState != TBLOCK_STARTED)
|
||||
CurrentTransactionState->blockState != TBLOCK_STARTED)
|
||||
elog(ERROR, "cannot prevent transaction chain");
|
||||
/* all okay */
|
||||
}
|
||||
@ -1462,6 +1462,36 @@ RequireTransactionChain(void *stmtNode, const char *stmtType)
|
||||
stmtType)));
|
||||
}
|
||||
|
||||
/*
|
||||
* IsInTransactionChain
|
||||
*
|
||||
* This routine is for statements that need to behave differently inside
|
||||
* a transaction block than when running as single commands. ANALYZE is
|
||||
* currently the only example.
|
||||
*
|
||||
* stmtNode: pointer to parameter block for statement; this is used in
|
||||
* a very klugy way to determine whether we are inside a function.
|
||||
*/
|
||||
bool
|
||||
IsInTransactionChain(void *stmtNode)
|
||||
{
|
||||
/*
|
||||
* Return true on same conditions that would make PreventTransactionChain
|
||||
* error out
|
||||
*/
|
||||
if (IsTransactionBlock())
|
||||
return true;
|
||||
|
||||
if (!MemoryContextContains(QueryContext, stmtNode))
|
||||
return true;
|
||||
|
||||
if (CurrentTransactionState->blockState != TBLOCK_DEFAULT &&
|
||||
CurrentTransactionState->blockState != TBLOCK_STARTED)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Register or deregister callback functions for end-of-xact cleanup
|
||||
|
Reference in New Issue
Block a user