mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 10:30:33 +03:00 
			
		
		
		
	Add NOWAIT option to SELECT FOR UPDATE/SHARE.
Original patch by Hans-Juergen Schoenig, revisions by Karel Zak and Tom Lane.
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| <!-- | ||||
| $PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.88 2005/07/14 06:17:36 neilc Exp $ | ||||
| $PostgreSQL: pgsql/doc/src/sgml/ref/select.sgml,v 1.89 2005/08/01 20:31:04 tgl Exp $ | ||||
| PostgreSQL documentation | ||||
| --> | ||||
|  | ||||
| @@ -30,7 +30,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="parameter">expression</replac | ||||
|     [ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC | USING <replaceable class="parameter">operator</replaceable> ] [, ...] ] | ||||
|     [ LIMIT { <replaceable class="parameter">count</replaceable> | ALL } ] | ||||
|     [ OFFSET <replaceable class="parameter">start</replaceable> ] | ||||
|     [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] ] | ||||
|     [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] ] | ||||
|  | ||||
| where <replaceable class="parameter">from_item</replaceable> can be one of: | ||||
|  | ||||
| @@ -151,7 +151,7 @@ where <replaceable class="parameter">from_item</replaceable> can be one of: | ||||
|     </listitem> | ||||
|    </orderedlist> | ||||
|   </para> | ||||
|     | ||||
|  | ||||
|   <para> | ||||
|    You must have <literal>SELECT</literal> privilege on a table to | ||||
|    read its values.  The use of <literal>FOR UPDATE</literal> or | ||||
| @@ -506,7 +506,7 @@ HAVING <replaceable class="parameter">condition</replaceable> | ||||
|     <replaceable class="parameter">select_statement</replaceable> is | ||||
|     any <command>SELECT</command> statement without an <literal>ORDER | ||||
|     BY</>, <literal>LIMIT</>, <literal>FOR UPDATE</literal>, or | ||||
|     <literal>FOR SHARE</literal> clause.  | ||||
|     <literal>FOR SHARE</literal> clause. | ||||
|     (<literal>ORDER BY</> and <literal>LIMIT</> can be attached to a | ||||
|     subexpression if it is enclosed in parentheses.  Without | ||||
|     parentheses, these clauses will be taken to apply to the result of | ||||
| @@ -803,14 +803,14 @@ OFFSET <replaceable class="parameter">start</replaceable> | ||||
|    <para> | ||||
|     The <literal>FOR UPDATE</literal> clause has this form: | ||||
| <synopsis> | ||||
| FOR UPDATE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] | ||||
| FOR UPDATE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] | ||||
| </synopsis> | ||||
|    </para> | ||||
|  | ||||
|    <para> | ||||
|     The closely related <literal>FOR SHARE</literal> clause has this form: | ||||
| <synopsis> | ||||
| FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] | ||||
| FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] | ||||
| </synopsis> | ||||
|    </para> | ||||
|  | ||||
| @@ -831,6 +831,18 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] | ||||
|     linkend="mvcc">. | ||||
|    </para> | ||||
|  | ||||
|    <para> | ||||
|     To prevent the operation from waiting for other transactions to commit, | ||||
|     use the <literal>NOWAIT</> option.  <command>SELECT FOR UPDATE | ||||
|     NOWAIT</command> reports an error, rather than waiting, if a selected row | ||||
|     cannot be locked immediately.  Note that <literal>NOWAIT</> applies only | ||||
|     to the row-level lock(s) — the required <literal>ROW SHARE</literal> | ||||
|     table-level lock is still taken in the ordinary way (see | ||||
|     <xref linkend="mvcc">).  You can use the <literal>NOWAIT</> option of | ||||
|     <xref linkend="sql-lock" endterm="sql-lock-title"> | ||||
|     if you need to acquire the table-level lock without waiting. | ||||
|    </para> | ||||
|  | ||||
|    <para> | ||||
|     <literal>FOR SHARE</literal> behaves similarly, except that it | ||||
|     acquires a shared rather than exclusive lock on each retrieved | ||||
| @@ -843,7 +855,8 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] | ||||
|    <para> | ||||
|     It is currently not allowed for a single <command>SELECT</command> | ||||
|     statement to include both <literal>FOR UPDATE</literal> and | ||||
|     <literal>FOR SHARE</literal>. | ||||
|     <literal>FOR SHARE</literal>, nor can different parts of the statement use | ||||
|     both <literal>NOWAIT</> and normal waiting mode. | ||||
|    </para> | ||||
|  | ||||
|    <para> | ||||
| @@ -861,8 +874,8 @@ FOR SHARE [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] | ||||
|    </para> | ||||
|  | ||||
|    <para> | ||||
|     It is possible for a <command>SELECT</> command using both  | ||||
|     <literal>LIMIT</literal> and  <literal>FOR UPDATE/SHARE</literal>  | ||||
|     It is possible for a <command>SELECT</> command using both | ||||
|     <literal>LIMIT</literal> and  <literal>FOR UPDATE/SHARE</literal> | ||||
|     clauses to return fewer rows than specified by <literal>LIMIT</literal>. | ||||
|     This is because <literal>LIMIT</> is applied first.  The command | ||||
|     selects the specified number of rows, | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| <!-- | ||||
| $PostgreSQL: pgsql/doc/src/sgml/ref/select_into.sgml,v 1.35 2005/04/28 21:47:10 tgl Exp $ | ||||
| $PostgreSQL: pgsql/doc/src/sgml/ref/select_into.sgml,v 1.36 2005/08/01 20:31:04 tgl Exp $ | ||||
| PostgreSQL documentation | ||||
| --> | ||||
|  | ||||
| @@ -31,7 +31,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac | ||||
|     [ ORDER BY <replaceable class="PARAMETER">expression</replaceable> [ ASC | DESC | USING <replaceable class="PARAMETER">operator</replaceable> ] [, ...] ] | ||||
|     [ LIMIT { <replaceable class="PARAMETER">count</replaceable> | ALL } ] | ||||
|     [ OFFSET <replaceable class="PARAMETER">start</replaceable> ] | ||||
|     [ FOR { UPDATE | SHARE } [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ] ] | ||||
|     [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] ] | ||||
| </synopsis> | ||||
|  </refsynopsisdiv> | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| <!-- | ||||
| $PostgreSQL: pgsql/doc/src/sgml/sql.sgml,v 1.37 2005/07/14 06:17:35 neilc Exp $ | ||||
| $PostgreSQL: pgsql/doc/src/sgml/sql.sgml,v 1.38 2005/08/01 20:31:05 tgl Exp $ | ||||
| --> | ||||
|  | ||||
|  <chapter id="sql-intro"> | ||||
| @@ -865,7 +865,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="PARAMETER">expression</replac | ||||
|     [ ORDER BY <replaceable class="PARAMETER">expression</replaceable> [ ASC | DESC | USING <replaceable class="PARAMETER">operator</replaceable> ] [, ...] ] | ||||
|     [ LIMIT { <replaceable class="PARAMETER">count</replaceable> | ALL } ] | ||||
|     [ OFFSET <replaceable class="PARAMETER">start</replaceable> ] | ||||
|     [ FOR { UPDATE | SHARE } [ OF <replaceable class="PARAMETER">class_name</replaceable> [, ...] ] ] | ||||
|     [ FOR { UPDATE | SHARE } [ OF <replaceable class="parameter">table_name</replaceable> [, ...] ] [ NOWAIT ] ] | ||||
|      </synopsis> | ||||
|     </para> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user