11g child table update locking
Hi,
I'm posting this question after searching on multiple places and trying to understand 11g locking mechanism.
I've a table TXN1 transaction and has FKs to 3 different tables Account, customer, country and currency. ALL FKs are indexed (bitmap). I am updating TXN1 of amount column about 10,000 rows. (SID 1) As expected, it has taken lock type 3 SX on TXN1. But it has taken on lock type 4 (share) on Account, customer and country. Committing every 10k rows.
At the same time sid 2 is inserting into another TXN2 table which has FK to the same dimensions account, customer and currency. Only FK on ac_id is bitmap indexed. The inserts have taken SX lock(type 3) on tXN2 table (expected). But it is trying to take SX type 3 lock on account, customer, currency tables. typ3 lock taken on CCY but waiting on CST. But It is blocked by sid 1. It has resulted into Enque-TM contention and resulted into anywhere 60-300 secs wait time..
I understand update/delete in parent table results into locking of SX of child tables and need the FKs to be indexed to avoid etc. I didn't understand the following and appreciate if someone can help me.
1. Why is SID1 taking shared lock on the parent tables Account,customer,country and currency tables? The update statement is not updating any of those FK columns nor referring them in where clause(if it matters!). Is it to ensure that the parent rows are not deleted?
2. Why is SID2 taking SX lock on the dimension tables? Why is it not taking RS lock type 2 on parent rows? Why is SID1 taking shared lock type 4, but not 2?
Thanks
Ram
Edited by: rkuppa on May 24, 2013 2:24 PM
Edited by: rkuppa on May 24, 2013 2:25 PM
Edited by: rkuppa on May 24, 2013 2:26 PM
Edited by: rkuppa on May 24, 2013 2:33 PM
Edited by: rkuppa on May 26, 2013 4:49 PM
Table TxN(ac_id, cs_id, amt, amt_dollar), PK on ac_id,cs_id. constraint FK on ac_id to Table AC_DIM (ac_id, acctname), FK on cs_id to Table CST_DIM(cs_id, custname). These FK are bitmap indexed.
Update qry: update TXN set amt_dollar =amt/1.1 where rownum<1000; commit; (sid 308)
Table TXN2(ac_id, cs_id,ccy_id, amt, amt_dollar), PK on ac_id,cs_id,ccy_id. constraint FK on ac_id to Table AC_DIM (ac_id, acctname), FK on cs_id to Table CST_DIM(cs_id, custname), CCY_DIM(ccy_id). Only ac_id FK in the TXN2 table is indexed to bitmap.
At the same time, another transaction is inserting into TXN2 1000 rows. (sid 127)
SELECT l.sid, s.blocking_session blocker, SUBSTR(s.event,1,20),
l.type, l.lmode, l.request, o.object_name, o.object_type
FROM v$lock l, dba_objects o, v$session s
WHERE UPPER(s.username) = 'MY_USER'
AND l.id1 = o.object_id (+)
AND l.sid = s.sid
ORDER BY sid, type;
SID BLOCKER SUBSTR(S.EVENT,1,20) TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
308 db file scattered re AE 4 0 ORA$BASE EDITION
308 db file scattered re TM 4 0 AC_DIM TABLE
308 db file scattered re TM 4 0 CST_DIM TABLE
308 db file scattered re TM 3 0 TXN TABLE
127 308 enq: TM - contention AE 4 0 ORA$BASE EDITION
127 308 enq: TM - contention TM 3 0 CCY_DIM TABLE
127 308 enq: TM - contention TM 0 3 CST_DIM TABLE
*<< I don't see type 3 lock on AC_DIM for sid 127>>*
SELECT
S.SID,
S.PROGRAM,
S.SQL_HASH_VALUE,
L.REQUEST,
L.ID1,
L.ID2,
L.LMODE,
L.TYPE,
L.BLOCK
FROM
V$LOCK L,
V$SESSION S
WHERE
(L.ID1, L.ID2, L.TYPE) IN
(SELECT
ID1,
ID2,
TYPE
FROM
V$LOCK
WHERE
REQUEST > 0)
AND L.SID=S.SID;
SID PROGRAM SQL_HASH_VALU REQUEST ID1 ID2 LMODE TYPE BLOCK
308 SQL Developer 1733825831 0 509281 0 4 TM 1
127 db-load.impl.n64@aittsmwp2 (TNS V1-V3) 4097376515 3 509281 0 0 TM 0Edited by: rkuppa on May 24, 2013 6:58 PM
Edited by: rkuppa on May 24, 2013 7:12 PM
Edited by: rkuppa on May 24, 2013 7:16 PM
Edited by: rkuppa on May 26, 2013 4:42 PM
Edited by: rkuppa on May 26, 2013 4:47 PM
Edited by: rkuppa on May 26, 2013 4:55 PM
Similar Messages
-
Hello Gurus..... ISSUE with child Table update
I have an issue with child table update
I have created a GTC with one parent table and two child tables. I'm able to update the parent table and the values are found in db, but the ISSUE is the child Table values are not updating the db.
please give me a solution
regards
SrikanthIf you are keeping referential integrity in the database, not in the application, it is easy to find the child and parent tables. Here is a quick and dirty query. You can join this to dba_cons_columns to find out on which columns the referential constraints are defined. This lists all child-parent table including SYS and SYSTEM users. You can run this for specific users of course.
select cons1.owner child_owner,cons1.table_name child_table,
cons2.owner parent_owner,cons2.table_name parent_table
from dba_constraints cons1,dba_constraints cons2
where cons1.constraint_type='R'
and cons1.r_constraint_name=cons2.constraint_name; -
Parent-Child Table Update via Single Stored Procedure
Uses: Oracle 9i Server via a Remote Connection with restriction, Oracle 9i client, .NET 2.0+System.Data.Oracle namespace, Delphi+BDE;
I have an entry form which consists of a parent and a child table. I'm so keen in knowing whether there is any possibilities of updating the records via a single stored procedure? I mean if parent have a single record and corresponding to it, child have few records (more than 1 rows). I need to take the parent's value and child's value send it to the stored procedure and update it.
Regards,The entry form gets the raw data from the user. So yes the data is captured front end but not updated nor processed. Once the user clicks "Save" or what ever the values are taken to the SP. In the SP the operations are done either as update or insert. Lets concentrate on Inserts only at the moment.
I.e. there are 2 tables as:
tbl_Payment(_PaymentID_, PaymentMode,PaymentDate, TotalPaymentValue);
tbl_PaymentAccount(_PaymentID,AccountID_,PaymentValue);
So the form has a top part which is bounded to the Parent Table which is "tbl_Payment" to few text boxes, and below it has a Datagrid, bounded to Child Table which is "tbl_PaymentAccount". And assume the the Single Stored Procedure as "sp_payment_addchg".
I can pass newly entered values to the SP as:
Command.Text = "sp_payment_addchg";
/*so all the parent table bounded values are updated as*/
Command.Parameter[0].value = text1.text;
Command.Parameter[1].value = text2.text;
and so on
Since the DataGrid may have multiple rows, I cant figure it out how to get those rows into a single parameter.
Regards, -
Updating a row in table exclusive lock on entire table
Hi
We have table master table and few child tables .
when we try to update a row in master table , it is locking entire table
i.e seems update process holding exclusive lock on entire table
it is not allowing any furthur update to that table
Could you please tell me what could be the problem for that
Thanks,
- AKDoes the table has primary key - foreign key relationship? Try disabling the constraint and see if it works. If it works then it is about unindexed foreign key issue.
-
UPDATE of column in parent only UPDATEs first row in DENORMALIZED child table
In the Repositiry in Designer 6i, I denormalized DESC1 column to
pull the value of DESC1 in the parent table. The child table has
four (4) records with matching foreign keys. When I go into my
Form and update DESC1 in the parent, only the first of the four
child DESC1's are updated. Any ideas?
Thanks,
DanDan,
Sorry, known bug, but should be fixed in next release.
Have a look via metalink at article <Note:156833.1> this
explains in detail the problem and a fix.
The bug no was <1974122>
regards
David -
Cascade update of primary key in child tables
Hi,
We have a typical scenario in which the primary key has to propage to the child table into 3 levels. We are getting the no parent key exception if we create new data into the three tables using 3 level master detail relationship and execute commit operation. The following is the structure of the tables.
Parent_table (sno number primary key, name varchar2(100));
Child_table (fk_sno number primary key, name varchar2(100), foreign key (fk_sno) references parent_table(sno));
GrandChild_table (sno number primary key, fk_sno number, name varchar2(100), foreign key (fk_sno) references Child_table(fk_sno));
The requirement is to update fk_sno in child_table and grandchild_table with the trigger generated primary key sno in the parent_table.
The application module is having the following structure
parenttable
|
----------childtable
|
-----------grandchild_table
If we create new records into parent_table and child_table it is working fine when we commit the data. If we create another record into grandchild_table and commit data we are getting the foreign key violation exception. We are using composition in the association to update the modified values to refresh the data.
Is there any problem in the data model to use fk_sno as primary key and foreign key in child_table.
Thanks and Regards,
S R PrasadHmm, another example is CSKS, this logic was probably designed already in the 1980s...maybe it was seen beneficial to be able to select the currently valid record by using the primary key only (the first record where DATBI is larger than system date, not possible when DATAB is the key instead).
Maybe there are better explanations. Why do you need to know this, just curious?
Thomas -
Update column data to Upper Case in parent and child table
Hi ,
I am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
when updating parent row:
ORA-02292: integrity constraint (XXXXXXXXXXXXXX_FK) violated - child record found
When updatng corresponding child row:
ORA-02291: integrity constraint (XXXXXXXXXXXXXXXX_FK) violated - parent key not found
how can i update on both the places ?
Regards,
AAI am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
Why do you need to do that?
That is just ONE of several questions you should answer before you start modifying your data.
1. What is your 4 digit Oracle version? (result of SELECT * FROM V$VERSION)
2. If both values are the same case what difference does it make what that case is?hen you don't need to alter your original data.
3. What is the source of the column values you are using now? If you change your data to upper case it will no longer be identical to the source data.
4. What is your plan for enforcing future values to be stored in UPPER case? Are you going to use a trigger? Have you written and tested such a trigger to see if it will even work the way you expect?
5. Why aren't you using a surrogate key instead of a 'business' data item? You have just demonstrated one reason why surrogate keys can be useful: their actual value is NOT important.
You should reexamine your problem and architecture and consider other alternatives.
One alternative is to add a new 'surrogate key' column to use as the primary key. Just create a new sequence and use a trigger to populate the new column. Your current plans will require a trigger to perform the case conversion so instead of the just use the trigger to provide the value.
If the change is being done to facilitate searching you could just add a VIRTUAL column UPPER_MY_COLUMN and index that instead. Then you could search on that new virtual column and the data values would still be identical to the original data source. -
Following is my Query unable to update when Executed table gets lock Execution does not stop even for an hour.
update Employees
set Status = 'Close'
where statusid IN (select statusid
from MyView
where DownloadedDate ='2014-07-27 00:00:00.000'
here Employee contains 3,00,000 of records and Subquery return 1,50,000 Empid
i tried in various ways but not able to solve, statusid column have no index on, i tried using cursor but it does not work.
plz let me know how to solve this Issue, THANKS IN ADVANCE.Hello,
You should better post your question to a more related Forum, like Transact-SQL or SQL Server Database Engine; this Forum is for samples & community Projects.
Have you checked the execution plan if indexes are used?
You could update the data in chunks, e.g. 10.000 rows per execution. For this you have to add a TOP clause and a filter to update only those, who are not updated yet.
update TOP (10000) Employees
set Status = 'Close'
where statusid IN
(select statusid
from MyView
where DownloadedDate ='2014-07-27 00:00:00.000')
AND Status <> 'Close'
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Following is my Query, which unables to update. When Executed, table gets lock and Execution does not stop even for an hour.
update Employees
set Status = 'Close'
where statusid IN (select statusid
from MyView
where DownloadedDate ='2014-07-27 00:00:00.000'
here Employee contains 3,00,000 of records and Subquery return 1,50,000 Empid
i tried in various ways but not able to solve, statusid column have no index on, i tried using cursor but it does not work.
plz let me know how to solve this Issue, Its very Important to get solve as all my further work depends on Updation
, THANKS IN ADVANCE.See also your other thread with the same question:
http://social.msdn.microsoft.com/Forums/en-US/80243625-fc3b-4ee1-bce1-4adcdbc16c14/unable-to-update-when-executed-table-gets-lock-execution-does-not-stop-execution-even-for-an-hour?forum=sqlserversamples
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Update key in parent and child tables
Situation:
Parent table (p) has a PK, p.parent_id. Child table (c) has a FK c.parent_id which, of course, points back to PK, p.parent_id.
I need to UPDATE the key in both tables but I am concerned about throwing a FK constraint violation. How does one get around this? Does one update the child first then the parent or vice versa? Seems either way a FK violation will occur...
thank u.1) If you ever anticipate wanting to update a key, that key should not be the primary key of a table. Primary keys should be immutable. If this is going to happen with any regularity, you need to re-examine the underlying data model.
2) If the constraints were declared to be deferrable, you would simply mark them as deferred, update both tables, and commit (at which point the constraint would be validated). If the constraints were not declared to be deferrable, you will probably need to end up dropping and re-creating one or the other (presumably as a deferrable constraint this time).
Justin -
How to update parent and child tables while updating parent table
I have a parent table EMPLOYEE which includes columns (sysid, serviceno,employeename...) sysid is Primary key, serviceno is Unique key and I have child table DEPENDENT includes columns (sysid,employee_sysid,name,dob...) here again SYSID is primary key for DEPENDENTS table, employee_sysid is Foreign key of EMPLOYEE table.
Now I want to change SYSID (using sequence) in EMPLOYEE table which need to be update in DEPENDENTS table as well
Note: I have 10000 records in EMPLOYEE table as well as I have 5 more child tables which need to update new SYSID.
please help mefirst disable the FOREIGN KEY Constraints.
you can update Parent as well as Child record also with help of trigger.
here i am giving you one examlpe..it may help u.
create table parent(id number primary key,name varchar2(100))
create table child_1(id number primary key,p_id number,dob date,
CONSTRAINT FK_id FOREIGN KEY (p_id) REFERENCES parent (ID))
create table child_2(id number primary key,p_id2 number,addr varchar2(1000),
CONSTRAINT FK_id2 FOREIGN KEY (p_id2) REFERENCES parent (ID))
insert some test data to parent and child tables.
alter table child_2 disable constraint FK_id2
alter table child_1 disable constraint FK_id2
CREATE OR REPLACE TRIGGER delete_child
BEFORE UPDATE ON parent
FOR EACH ROW
BEGIN
UPDATE CHILD_1
SET P_ID=:NEW.ID
WHERE P_ID=:OLD.ID;
UPDATE CHILD_2
SET P_ID2 =:NEW.ID
WHERE P_ID2=:OLD.ID;
END;
then Upadte parent table primary key col and check the child tables.
then enable the constraints... -
Update data to upper case in parent/child tables
Hi Gurus!
In production we have a product table and which is being reference by many tables making it parent child relationship. By mistake, we realized that last month some product were added in lower case and now we got a request to update all these product codes to upper case so that the existing code that use these tables have no impact. Appreciate if you can give some idea on how can I update the existing data in the parent table to upper case along with the child records?
Regards
SriAre the product code that you need to update what is stored in the child tables? If so, then you would need to do it in several steps, something like:
Identify the child tables
SELECT table_name, constraint_name
FROM user_constraints
WHERE r_constraint_name = (SELECT constraint_name
FROM user_constraints
WHERE table_name = 'PRODUCT_TABLE' and
constraint_type = 'P');Create the new upper case product code in product table:
INSERT INTO product_table
SELECT UPPER(product_code), other_columns
FROM product_table
WHERE product_code <> UPPER(product_code);Update the child tables to uppercase the product codes
UPDATE child1
SET product_code = UPPER(product_code)
WHERE product_code <> UPPER(product_code);finally, delete the lower case product codes from product_table
DELETE FROM product_table
WHERE product_code <> UPPER(product_code);John -
Parent values should be enter into child table in 11g adf
HI ALL,
i' m using oracle 9i with 11g adf jdeveloper.
I have one parent table and child table respectively . I'm display both the parent and child table in one jsf page.Some fields/records in child table have same as in parent table.so when we enter values in parent fields the child table value should be placed.
Ex:
PARENT TABLE
ID
NAME
LOC
SAL
DEPART
COMP
CHILD TABLE
CID
PID
CNAME
LOC
SAL
DEPART
CNO
CPNR
LOC,SAL and DEPART are common fields in both tables
I display all the feilds in parent table , but i won't display LOC,SAL and DEPART field from Child table . Now i when i fill value in fields and fire submit . the values of LOC,SAL and DEPART parent table values should be enter in child table fields
Thanks in advance.Create a custom Application Module method and expose it to the AM client interface. In it set the child VO attributes from the parent VO and submit. Bind this custom method to your Submit in the ViewController and call it from a backing bean.
Regards,
Nick -
OIM 11g: Email template - child table columns
Hi All
How can I fetch the child table (process form child table) columns in the OOTB email templates. When I select Process form data on the email definition screen on Design console, I am only able to select the main process form's columns.
Please help. Its urgent.OOTB not possible you have to write code for fetching child data.
I suggest send mail using custom code and fetch child data using OIM APIs. -
Master Child tables how to get the latest rows from both
Hi,
Need some help with the sql. I have two tables Master & Child. In my Master table I have multiple rows for the same record and in the child table also multiple rows for the same master row how can I get the latest one's from both.
For example Data in my Master table looks like
CONT_ID SEQ_NUM DESCRIPTION
1 189 Update 2
1 188 Update 1
1 187 NewNow in the child table for the same CONT_ID I may have the following rows
CONT_ID UPDATED_DATE STATUS
1 3/16/2010 2:19:01.552700 PM P
1 3/16/2010 12:29:01.552700 PM A
1 3/16/2010 12:29:01.552700 PM P
1 3/16/2010 12:19:01.552700 PM NIn my final query how can I get the row with seq_num 189 as it's the latest in Master table and from child table the row with status of P as it's the latest one based on the time. Here is the query i have but it returns the latest row from the child table only and basically repeats the master table rows as opposed to one row that is latest from both:
ThanksHi,
You can use the analytic ROW_NUMKBER function to find the latest row for each cont_id in each table:
WITH got_m_rnum AS
SELECT cont_id, seq_num, description
, ROW_NUMBER () OVER ( PARTITION BY cont_id
ORDER BY seq_num DESC
) AS m_rnum
FROM master_table
-- WHERE ... -- any filtering goes here
, got_c_rnum AS
SELECT cont_id, updated_date, status
, ROW_NUMBER () OVER ( PARTITION BY cont_id
ORDER BY updated_date DESC
) AS c_rnum
FROM child_table
-- WHERE ... -- any filtering goes here
SELECT m.cont_id, m.seq_num, m.description
, c.updated_date, c.status
FROM got_m_rnum m
JOIN got_c_rnum c ON m.cont_id = c.cont_id
AND m.m_rnum = c.c_rnum
AND m.m_rnum = 1
;If you'd like to post CREATE TABLE and INSERT statements for the sample data, then I could test this.
If there happens to be a tie for the latest row (say, there are only two rows in the child_table with a certain cont_id, and both have exactly the same updated_date), then this query will arbitrarily choose one of them as the latest.
Maybe you are looking for
-
Can 2 users on one computer share 1 itunes music folder?
There must be a way to do this, I just can't seem to find the answer. The reason I need to do this is my ancient PowerBook only recognizes my new iPhone on one userid, not the one where all my music is loaded. Thanks in advance for any help you can p
-
What's causing this phatom space in Safari and Chrome but not FF
http://www.energyschool.com/CSES_Home/Resources.html I'm not figuring it out.
-
What is the max number of New-MailboxExportRequest that can be InProgress at the same time?
I haven't been able to find an answer for this, so I'm hoping someone can clarify off the top of their head. If you queue up a large number of New-MailboxExportRequests, how many of them can be "InProgress" at once? I'm assuming there is an upper lim
-
How do you upload a folder to a FTP site?
I want to publish a .com site to the web. I was told to sign up to a FTP "client". So I chose Fetcher. I published the site to a desk top folder. (Did I really "publish" anything if no one can read it?) Apple HELP then tells me to "download an FTP cl
-
Hi All, I am using Export to Excel functionality in my application. When I am running my application, I am getting the following error. <i> [wdgen] WARNING: Metadata of component ViewAdListNoPriceComp is not valid! ContextElementMapping "//WebDyn