![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, here are the requirements that I'm messing with: - Oracle 10g - Table like this CREATE TABLE TMP_TABLE * ( * * PKID * INTEGER NOT NULL ENABLE, -- Sequence * * FIELD1 VARCHAR2(45) NOT NULL ENABLE, * * FIELD1 VARCHAR2(45) NOT NULL ENABLE, * * STATUS CHAR(1) DEFAULT '0' NOT NULL ENABLE, -- 0 free (unset) , 1 reserved (set) * * CONSTRAINT TMP_TABLE_PK PRIMARY KEY (PKID) USING INDEX ENABLE * ) ; with about hundreds of thousands records. - Stored procedure should be Select the first available 10 records with status=0 (no sorting required), update status=1 and returns the selected rows into a ref cursor (Java Oracle.CURSOR) with the TMP_TABLE%ROWTYPE. - Stored procedure should be called by concurrent processes: no more one process must select the same 10 records (PKIDs). I'm starting with create or replace PACKAGE PKGTEST IS * TYPE vCursor IS REF CURSOR RETURN TMP_TABLE%ROWTYPE; END PKGTEST; / CREATE OR REPLACE * PROCEDURE pSelectTMP( * * O OUT PKGTEST.VCURSOR * * ) * AS * * PRAGMA AUTONOMOUS_TRANSACTION; BEGIN -- -- Something I don't know to do... -- COMMIT; END pSelectTMP; / If REF CURSOR can't be used... I could change also the Java-side client to manage anything else (VARRAY?). I'v tried with the UPDATE ... RETURNING clause without success... Thanks in advance Best regards, M. |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
I hate to make suggestions without knowing what you are really after but here goes: |
|
Have the action select the keys to use via a stored function that uses an anonymous transaction to select 10 rows where the status = 0 using select for update nowait, immediately update the status, commit, and pass the selected keys back to your applicaiton. I would think that this process would also need to update the selected rows with information identifing the selecting process so the rows can be marked freed if the application does not use them. |
#5
| |||
| |||
|
|
b) it marks freed those rows and pass them to an external client |
#6
| |||
| |||
|
|
So I'm able to obtain a Java result set through the Sys_RefCursor. I'm not really sure that is a "multi-process access" safe procedure... |
#7
| |||
| |||
|
|
On Feb 8, 12:29 am, Mau C <nob... (AT) hotmail (DOT) com> wrote: [...] Here are some examples: http://asktom.oracle.com/pls/asktom/...:4530093713805 |
#8
| |||
| |||
|
|
Il 08/02/2011 18.51, joel garry ha scritto: On Feb 8, 12:29 am, Mau C <nob... (AT) hotmail (DOT) com> wrote: [...] Here are some examples:http://asktom.oracle.com/pls/asktom/..._QUESTION_ID:4... I see that the "simple" FOR UPDATE clause is not enough. So I've foundhttp://tinyurl.com/69mkw3c and SKIP LOCKED seems to be the right way to avoid problems in high concurrency process contention. So, my stored should be changed in ... CURSOR c1 IS SELECT pkid, * * field1, * * field2 * FROM tmp_table * WHERE status=0 * AND rownum <=10 FOR UPDATE OF status SKIP LOCKED; .. FOR cur_row IN c1 LOOP .. UPDATE tmp_table SET status=1 WHERE CURRENT OF c1; END LOOP; COMMIT; .. Does anybody agree ? Regards, M. |
#9
| |||
| |||
|
|
Il 08/02/2011 18.51, joel garry ha scritto: On Feb 8, 12:29 am, Mau C<nob... (AT) hotmail (DOT) com> wrote: [...] Here are some examples: http://asktom.oracle.com/pls/asktom/...:4530093713805 I see that the "simple" FOR UPDATE clause is not enough. So I've found http://tinyurl.com/69mkw3c and SKIP LOCKED seems to be the right way to avoid problems in high concurrency process contention. So, my stored should be changed in ... CURSOR c1 IS SELECT pkid, field1, field2 FROM tmp_table WHERE status=0 AND rownum<=10 FOR UPDATE OF status SKIP LOCKED; .. FOR cur_row IN c1 LOOP .. UPDATE tmp_table SET status=1 WHERE CURRENT OF c1; END LOOP; COMMIT; .. Does anybody agree ? Regards, M. |
#10
| |||
| |||
|
|
Mau C wrote: Il 08/02/2011 18.51, joel garry ha scritto: On Feb 8, 12:29 am, Mau C<nob... (AT) hotmail (DOT) com> *wrote: [...] Here are some examples:http://asktom.oracle.com/pls/asktom/..._QUESTION_ID:4... I see that the "simple" FOR UPDATE clause is not enough. So I've foundhttp://tinyurl.com/69mkw3c and SKIP LOCKED seems to be the right way to avoid problems in high concurrency process contention. So, my stored should be changed in ... CURSOR c1 IS SELECT pkid, * * *field1, * * *field2 * *FROM tmp_table * *WHERE status=0 * *AND rownum<=10 FOR UPDATE OF status SKIP LOCKED; .. FOR cur_row IN c1 LOOP .. UPDATE tmp_table SET status=1 WHERE CURRENT OF c1; END LOOP; COMMIT; .. Does anybody agree ? Regards, M. I always agree with my own propositions. |
![]() |
| Thread Tools | |
| Display Modes | |
| |