How to check circular reference in data of millions of rows

Hi all,
I am new as an oracle developer.
I have a table(say table1) of hierarchical data with columns child_id and parent_id. The table has around 0.5 million records. There are around 0.2 million root level records are present.
I need to update some (the number variies on different conditions, might differ from 50K to 0.4 million) of the parent_ids from other table only if that do not cause any circular reference in data of table1.
I am using Oracle9i.
The approach I have tried is:
I copied all data from table1 to a work table table3. Update the parent_id on columns that matches the condition and updated a column source_table to table2.
I copied all the child_id from table2 that are to be updated into another table table4 and built tree for each of those childs. If it builds the tree successfully updated a column is_circular in the table3 to 0 and then deleted the child_id from table4.
This whole process needs to run recursively until no tree is built successfully in an iteration.
But this process is running slow and at the rate it is executing it would run for days for the 0.3 million records.
Please suggest a better way to do this.
The code I am using is :
INSERT /*+ append parallel (target,5) */
INTO table3 target
select /*+ parallel (src,5) */
child_id, parent_id, 'table1' source_table,null
from table1 src;
INSERT INTO table4
select distinct child_id, parent_id
from table2
where status_cd is null;
commit;
Update dtable3 a
set (parent_id,source_table) = (select parent_id,'table2' source_table
from table4 b
where b.child_id = a.child_id);
WHILE v_loop_limit<>v_new_count
LOOP
select count(1)
into v_loop_limit
     from table4;
-+-----------------------------------------------------------
--| You need to actually traverse the tree in order to
--| detect circular dependencies.
+-----------------------------------------------------------           
For i in 1 .. v_new_count
BEGIN
select child_id
into v_child_id from(
select child_id, row_number() over (order by child_id) pri from table4)
where pri = i;
SELECT COUNT (*) cnt
INTO v_cnt
FROM table3 dl
START WITH dl.child_id = v_child_id
CONNECT BY PRIOR dl.child_id = dl.parent_id ;
UPDATE table3SET is_circular = '0'
where child_id= v_child_id
and source_table = 'table2';
delete from table3
where child_id = v_child_id;
select count(1)
into v_new_count
     from table4;
COMMIT;
EXCEPTION WHEN e_infinite_loop
THEN dbms_output.put_line ('Loop detected!'||v_child_id);
WHEN OTHERS THEN
     dbms_output.put_line ('Other Exceptions!');
END;
END LOOP;
END LOOP;
Thanks & Regards,
Ruchira

Hello,
First off, if you're so new to a technology why do you brush off the first thing an experienced, recognized "guru" tells you? Take out that WHEN OTHERS ! It is a bug in your code, period.
Secondly, here is some code to try. Notice that the result depends on what order you do the updates, that's why I run the same code twice but in ASCENDING or DESCENDING order. You can get a circular reference from a PAIR of updates, and whichever comes second is the "bad" one.drop table tab1;
create table TAB1(PARENT_ID number, CHILD_ID number);
create index I1 on TAB1(CHILD_ID);
create index I2 on TAB1(PARENT_ID);
drop table tab2;
create table TAB2(PARENT_NEW number, CHILD_ID number);
insert into TAB1 values (1,2);
insert into TAB1 values (1,3);
insert into tab1 values (2,4);
insert into TAB1 values (3,5);
commit;
insert into TAB2 values(4,3);
insert into TAB2 values(3,2);
commit;
begin
for REC in (select * from TAB2 order by child_id ASC) LOOP
  merge into TAB1 O
  using (select rec.child_id child_id, rec.parent_new parent_new from dual) n
  on (O.CHILD_ID = N.CHILD_ID)
  when matched then update set PARENT_ID = PARENT_NEW
  where (select COUNT(*) from TAB1
    where PARENT_ID = n.CHILD_ID
    start with CHILD_ID = n.PARENT_NEW
    connect by CHILD_ID = prior PARENT_ID
    and prior PARENT_ID <> n.CHILD_ID) = 0;
end LOOP;
end;
select distinct * from TAB1
connect by PARENT_ID = prior CHILD_ID
order by 1, 2;
rollback;
begin
for REC in (select * from TAB2 order by child_id DESC) LOOP
  merge into TAB1 O
  using (select rec.child_id child_id, rec.parent_new parent_new from dual) n
  on (O.CHILD_ID = N.CHILD_ID)
  when matched then update set PARENT_ID = PARENT_NEW
  where (select COUNT(*) from TAB1
    where PARENT_ID = n.CHILD_ID
    start with CHILD_ID = n.PARENT_NEW
    connect by CHILD_ID = prior PARENT_ID
    and prior PARENT_ID <> n.CHILD_ID) = 0;
end LOOP;
end;
select distinct * from TAB1
connect by PARENT_ID = prior CHILD_ID
order by 1, 2;One last thing, be sure and have indexes on child_id and parent_id in your main table!

Similar Messages

  • How to break Circular References.

    I have on GUI class containing many components like Button, Combo Box, TextArea etc. And I have an other class ActionHandler which implements ActionListener,ItemListener and keyListener. GUI class has reference of ActionHandler class for handling events corresponding to the components in it and in ActionHandler class i need reference of GUI class for any modification/changes in the different GUI Components, based on the event generated.
    This results in circular referencing between the two classes. How to avoid this situation.

    I don't think circular references are necessarilly a bad thing. However I generally put the GUI listners etc. inside the GUI class to which they relate, so they naturally have access to the GUI class without an explict pointer. More often than not these listener objects are tiny anonymous classes which do little more than call a private method in theGUI class.

  • How to check if a physical data channel has data on it

    I am aquiring data continuously and am trying to check if there is data on the physical line, if there is digital data I want it to be passed to the next stage, if there is not I want the data diguarded. Is there a way of checking this digital line for inactivity because  when I suspend the data flow the clock continues to clock and my buffer just fills with empty data.
    Thanks 

    You should get a timeout error from the DAQmx Read if there is no data availalbe.  Are you not getting an error?
    As for your consumer loop, there is no need to check to see if there is data in the queue.  Just call the Dequeue Element.  If there is no data in the queue, then it sleeps until there is data (assuming you don't use a timeout).  It will then pass out the data as soon as it is available.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to check the last receiveing date of a specific material

    Dear Experts,
    I want to check the last receiving date of an specific material.  Is there any standard t.code ?
    Mov.Type 101, 103.
    Thanks in advance.
    Dinesh

    Hi,
    Transaction code MB51 used to list out the posting date of GR received material document number, date and quantity.
    This report is basically used for list out all the material document based on sort out of posting date, movement type (101 ,103 etc).
    There you can easily find it the posting date of the GR receiving.
    MC.A is the Analysis report which is used for analysis of Material total Goods receiving and goods issues -basic list.
    - I suggest to use report MB51 - based on receiving movement 101, transfer 301,311 etc or issues movement 201 posting date.
    Thanks and Regards,
    Thiru

  • How to check from which table data is picking by datasource 0CDCY_ACT_ATTR

    Hi Experts,
    Could you please help me in finding out of the table from which datasource 0CDCY_ACT_ATTR is extracting.
    As per my knowledge is should be extract from tables(infotypes) HRP5135 - 5141.If i am wrong please correct me.
    Issue : My extractor(0cdcy_ACT_ATTR) is bringing wrong ACT_TYPE (Eg :5010) where as in table HRP5141 for that particular OBJID it is 9180( different).
    Please help me why my extractor is bringing ACT_TYPE 5010.
    This standard datasource and using Function Module :  RCF_BIW_GET_ACTIVITY, How can i check from which table it is picking the data
    Thanks in Advanve
    Sree

    Hi Sree,
    In RSA3 on the first screen, you have the option to start debugging by marking the debug check box, once you put all the selections, click on execute and it will go to debug mode, then keep on pressing F5. It will debug your code line by line, then you can check for all the select statements.
    Or once the debugging is started you will have the option to put break point on all the select statements in one shot, you can get in touch with your ABAP team.
    Regards,
    Durgesh.
    Edited by: Durgesh Gandewar on Jul 24, 2011 8:20 PM

  • How to check the validation at data base level as well as current user ente

    Dear all
    i have creation page in that item code will not enter the duplicate values
    in that creation page contains advanced table
    user will click on create 15 blank records using add another row
    suppose in first row user will enter LAPTOP assume this item code
    in this case i need to raise exception through databse level
    in second row also user enter LAPTOP1 in this case exception will not raise becaause data is not there at databse
    in third row user will enter LAPTOP1 in this case item is not there in data base but it is there in second row in this case
    i need to raise exception
    how to achieve this
    Thanks in Advance
    Sreekanth

    You can validate this in form submission.
    1. Call a method in AMImpl.java
    2. loop the ViewObjects and check the values
    3. If you find a match, throw the error
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                   

  • How to  check customer reference no. not  being use more than once

    I have the following situation and appreciate if  some one could show me a simple solution.
    “On the Sales order window, when user enter a value for Customer Ref. No”, check if the entered value has already  been used on any existing Sales Order, and give message eg. “this Ref. No already been used in SO. 257”
    What is the easiest way of implementing the validation?
    Using Formatted Search?
    Triggers or Stored Procedure?
    Or one must go about doing this simple task using SDK, DIAPI?
    sample code illustrating solution would be much appreciated.
    I tried to create a query and used it with Formatted search on the Field, but failed on an error.
    the code using temporary hard coded value instead of $[$x.0.0] looks like this
    if (SELECT    COUNT(*)
    FROM         dbo.ORDR
    WHERE     (NumAtCard = 'AAA' and CardCode ='1234')
    ) =0     
         Begin
                       select 'AAA' --redisplay value
         end
    else
                  begin
    SELECT     TOP 1 'already used in SO '+ Convert(Char(3),DocEntry)
    FROM        dbo.ORDR
    WHERE     (NumAtCard = 'AAA')    
             end
    where 'AAA' is the reference no. to check for customer '1234', this code works when I run it in SQL query analyser, but failed when I run it as query in Business one. the idea was to redisplay the entered No. 'AAA' if it is not found in any existing SO for cust ='1234'
    can anyone point out what the error is or show  alternative code for the query.
    thanks

    Hi Andy,
    I believe the best way to do this is probably to use the SDK as (to my knowledge) this is the only way you can get a message to be displayed and to stop the actual processing of the document.
    If you want to go the formatted search route I would suggest you change your query a bit. I have played with your query and the following is an example as I got it working in SBO. I think SBO gets confused if there is more than one select statement that returns a result and I have started using variables to save the results of the select statements in.
    [code]Declare @Val varchar(100)
    declare @Count integer
    set @Val = $[$14.0.0]
    if (SELECT COUNT(*) FROM dbo.ORDR WHERE (NumAtCard = @Val and CardCode = $[$4.0.0])) > 0
    begin
    SELECT TOP 1 @Val = 'already used in SO '+ Convert(Char(3),DocEntry) FROM dbo.ORDR WHERE (NumAtCard = @Val)
    end
    select @Val[/code]
    I hope it helps a bit,
    Adele

  • How to refresh a table of data after inserting a row using ADF BC

    Hi,
    i am using ADF BC, JSF to construct a page to browse and another to create/update record. But after creating or updating the record it is not reflected when i come back to browse page.
    I tried to insert invokeaction in page definition page but i can not find the iterator bindings for that table in Binds option.
    can any one provide any example how to do it.
    Please help me.

    On the page def for your submit page, add inside the executables (on the structure pane) your iterator you want refreshed (if it isn't already there).
    Then double click on the submit button and bind it to a backing bean. My method in the backing bean looks like:
        if ( !operationBinding.getErrors().isEmpty() )
            return null;
        DCBindingContainer dcbindings = (DCBindingContainer)bindings;
        DCIteratorBinding appsIter = dcbindings.findIteratorBinding("ApplicationsIterator");
        appsIter.executeQuery();
        return null;
    }The executeQuery method will refresh that iterator for your return page. The "ApplicationsIterator" is what the structure pane calls your iterator. Works for me.
    Brian

  • How to update a column which has 35 millions of rows?

    Hi everyone
    need help
    I am updating a column which has 35 millions of records. When i start update, it is taking like > 60 mins and its not stoping (finishing).
    I need to null that column A, and update that column A  with the other column B values.
    Thanks
    kumar

    Three common causes for big updates that are slow:
    blocking. You can check whether the UPDATE is waiting on another connection to release locks using sp_who2
    improperly sized log file. A big update may use of a lot of log space. If you log file is too small, and you have auto-grow enabled (which is the default setting), it will grow whenever needed. But this takes a lot of extra time. You can easily see this
    when you view the file size of the log file
    if the column you are updating is indexed, the engine may also you tempdb a lot, so tempdb may also grow a lot, which would take a lot of additional time. This is also easy to check by inspecting tempdb's file size
    Gert-Jan

  • How to check manufacturing date of Z2?

    Hello, so the title pretty much sums it all. On earlier xperia phones you could check it under the battery, with xperia Z it was written on the back at the bottom but what about Z2? How to check it's manufacturing date?
    Solved!
    Go to Solution.

    Hi and welcome to the community! Since you're new please be sure that you have checked out our Discussion guidelines.
    This label can be found in the MicroSD-slot, check the following link:
    http://userguide.sonymobile.com/referrer.php?region=en&product=xperia-z2#IMEI-number.html
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • Circular references in Hashtable

    Hi,
    I was wondering if anyone could help me in determining when circular references appear in java.util.Hashtable I have written a class that serializes any arbitrary java object into XML. The problem occurs when the object contains many references to Hashtables. The serializer does not know how to handle circular references and goes into an infinite loop causing a stack overflow. Any help would be greatly appreciated.

    Hi.
    The solution is simple: keep all the processed objects in a set or map. Before sending an object check if it was already processed. If not, process it. If yes, place a reference in the XML file that will enable you to read find it during the read.
    Java Serialization uses a "serial number" for the objects it serializes. It keeps something like an HashMap of the objects already serialized. When writing, if it finds an object already writen it only writes its serial number. When reading a serial number it uses a map of the objects already read to find the object.
    Hope this helps,
    Nuno

  • To check the License Expiry Date on EP??

    Hello All,
                   I have completed installing Permanent Licenses through VA in SAP EP.How to check the license expiry date in a stand alone server like EP??Moreover can u pls tell me what authentication is required for applying licenses through slicense??I did some with sap* & the others with ddic??

    How to check the license expiry date in a stand alone server like EP??
    You can see the license and all the details of it in the licensing adaptor using Visual Admin.
    Moreover can u pls tell me what authentication is required for applying licenses through slicense??I did some with sap* & the others with ddic??
    Any user with SAP_ALL will do.... doesn't matter if you install some with SAP* and some with DDIC
    Regards
    Juan

  • Gantt view - multiple dates in the same row

    Hi,
    I created gantt view showing employees' vacations. Some of them have their holidays split into several dates (periods). How can I show those multiple dates in the same row in the gantt view? I can only show start date and end date of one vacation, but would
    like to enter multiple periods to be shown in the gantt view, in the same row.
    Thanks.

    You can't using the OOTB gantt chart so you would have to look at custom development or 3rd party web parts.
    Such as (blatant plug but it directly answers the OP question) my own companies Planner web part.
    http://www.pentalogic.net/sharepoint-products/planner
    The By Category view puts timelines on the same row so its ideal for things like vacation planning, room booking etc.
    This page shows it in use.
    http://blog.pentalogic.net/2010/08/sharepoint-staff-vacation-planner-absence-wall-chart-dashboard/

  • How to check validity of data reference

    Hello everybody,
    in my application I use a help class to buffer data objects.
    This class contains one attribute which is an internal table ( columns: DATAID and DATAREF )
    I use this databuffer to transport data between different classes.
    Now I did the following mistake:
    First I call the method 'METH_CHECK'. As import parameter I pass a reference to my databuffer class.
    In method 'METH_CHECK' I call a function module 'FUNC_1' passing my reference to my databuffer class.
    In 'FUNC_1'  I declare a local variable 'lv_value'.
    Then I use the statement 'GET REFERENCE OF lv_value' and save this reference into my databuffer class.
    After processing functions / methods I´m back at the point where 'METH_CHECK' was called.
    When I check my databuffer class, I´ve got one entry in it.
    The reference I saved while processing 'FUNC_1' . But the referenced data has already be freed ( remember, it was a local variable ).
    In the debugger I see the column where I save the references to data objects.
    The field value has changed from a valid reference to i.e. 'FREED ITAB: 5'...
    OK, I know what is wrong... No problem in my application, but I want to clean
    this entry... How can I check this...
    I can not check like
      LOOP AT me->buffer INTO wa_buffer.
        IF wa_buffer-data IS INITIAL.
          DELETE...
        ENDIF.
      ENDLOOP.
    or
      LOOP AT me->buffer INTO wa_buffer.
        IF wa_buffer-data CP 'FREED'.
          DELETE....
        ENDIF.
      ENDLOOP.
    How can I notice an invalid reference at this point?
    Thank you very much,
    Oliver Seifer

    Hello Oliver,
    Another approach might be to avoid any dependency to the caller at all.
    Regards
      Klaus
    data:
        buffer_Reference  type ref to data.
    field-symbols:
       <buffer_Data> type data.
    create data buffer_Reference like i_Value.
    assign buffer_Reference to <buffer_Data>.
    <buffer_Data> = i_Value.

  • How to check for archivelog backup on a particular date or time?

    Dear All,
    We have RMAN full database, cumulative and archivelog backup(eg location: Diskgroup A) scheduled on a regular period basis. Assume archivelog location is Diskgroup B. The diskgroup B became full and unable to archive further, since no space. Unable to connect to database, connect internal only until freed error. alert log also shows that archiver error. So the solution for this to clear some space in diskgroup B by removing some old archive logs. In our environment, everyday the archive logs are stored in a separated folder arranged in date wise.  I can do that . But before clearing some space, i need to make sure that the folder( or any date folder what im going to delete) is backed up or not. How to check that? Any idea please?
    eg: i have archivelogs like this in folders
    01_11_2013/
    02_11_2013/
    03_11_2013/
    04_11_2013/
    05_11_2013/
    06_11_2013/
    If i want to remove the folder 01_11_2013/( and its contents ie archivelogs) , how to check whether the archivelogs in this folder 01_11_2013/ is backed up or not?
    Regards,

    Pradeepcmst wrote:
    Dear All,
    We have RMAN full database, cumulative and archivelog backup(eg location: Diskgroup A) scheduled on a regular period basis. Assume archivelog location is Diskgroup B. The diskgroup B became full and unable to archive further, since no space. Unable to connect to database, connect internal only until freed error. alert log also shows that archiver error. So the solution for this to clear some space in diskgroup B by removing some old archive logs. In our environment, everyday the archive logs are stored in a separated folder arranged in date wise.  I can do that . But before clearing some space, i need to make sure that the folder( or any date folder what im going to delete) is backed up or not. How to check that? Any idea please?
    eg: i have archivelogs like this in folders
    01_11_2013/
    02_11_2013/
    03_11_2013/
    04_11_2013/
    05_11_2013/
    06_11_2013/
    If i want to remove the folder 01_11_2013/( and its contents ie archivelogs) , how to check whether the archivelogs in this folder 01_11_2013/ is backed up or not?
    Regards,
    rman> list backup;
    Which begs the question .. why is the FRA getting filled in the first place?  Is it seriously undersized?  Are you not doing regular housekeeping with rman 'delete obsolete' and 'backup archivelog delete input'

Maybe you are looking for

  • How to access the data in a TableView with build-in Dropdownlists

    Hi, I build up a TableView with DropdownListBoxes in the cells. All works so far but if I try to access the data in the cells I get the following error message :      at java.lang.Thread.run(Thread.java:479) Caused by: java.lang.reflect.InvocationTar

  • Error in Pre-DME

    Hello All Getting error message in Pre DME program R55 Error for personnel number and transfer number 76746 Is this a master data or program error Please advise us to fix this Regards sk

  • Would a 13" Macbook Pro (2.4GHz) be able to efficiently run Logic Pro?

    I'm thinking of buying a Macbook Pro, but I'm really tight on money. Would the lowest model of Macbook Pro still be able to efficiently run Logic Pro?   

  • PL/SQL function body return sql query, no data found problem

    Hi all, we are trying to build a dynamic report based on item selection by user. we are using SQL Query (PL/SQL function body returning SQL query). However when a user change the item and submit the page . The following error appears. ORA-01403: no d

  • Debugging Portal 4.0 in Eclipse?

    Has anyone gotten the EASIE WebLogic plugin for Eclipse to work with Portal 4.0? I can step through and properly debug my WLS6.1 apps, but run into all sorts of path problems for portal. I have to specify my WLS install directory as c:\bea\wlportal4.