0

I have the following oracle statement which some days ago worked quick and fine. When I run it now it takes forever:

MERGE INTO tablef f using
(
  select t.colf,t.colup
  from tablet t
  inner join (select max(created) as maxcreated 
              from tablet) mt 
   on t.created = mt.maxcreated) fu
on f.colf = fu.colf
WHEN MATCHED THEN
UPDATE SET f.aus = fu.colup

Or is there a way to reformulate the query to get it running again and faster?

The two tables involved have a primary key. For tablef the primary key is colf and for tablet the primary key is colf and created. Actually I also want to run this query from an SQL server database via an oracle linked server. And when I run this in SQL server management studio as follows:

execute ('MERGE INTO tablef f using
(
select 
t.colf,t.colup
from tablet t
inner join (select max(created) as maxcreated from tablet) mt on t.created = mt.maxcreated) fu
on f.colf = fu.colf
WHEN MATCHED THEN
UPDATE SET f.aus = fu.colup') AT ORACLELINKEDSERVER*

it runs without error and says 1 row affected. However if I check the data on the oracle database the row is not updated.

APC
  • 144,005
  • 19
  • 170
  • 281
  • 2
    It may sound silly but I want to know - DId you commit? – 1000111 Jul 15 '21 at 17:10
  • 1
    did you commit the change? changes will only be visible in the session making the change until they are formally committed. For the performance, has the amount of data changed significantly? It may help to recompile statistics on the tables involved. Also, indexes on any columns used as foreign keys may help. – pmdba Jul 15 '21 at 17:12
  • If you didn't commit from the SQL Server side... did you run the 'forever' Oracle-side version *afterwards* - in which case it may just be blocked by those uncommitted updates? (It's unclear if 'forever' means it took longer than expected but did eventually complete, or never completed.) – Alex Poole Jul 15 '21 at 17:34
  • *"some days ago worked quick and fine"* So what has changed? Probably you've got more data. Maybe you need to refresh your statistics? This is a performance issue. MERGE statements are like SELECT statements, we need details before we can offer tuning advice. Please read [this excellent post of advice](https://stackoverflow.com/a/34975420/146325) about asking Oracle optimization questions on this site. – APC Jul 16 '21 at 07:53
  • Silly question, does the tablef column created has an index, if not you force a full table scan of this table. – Cyrille MODIANO Jul 16 '21 at 18:49
  • Sorry guys, but yesterday I noted that the session from the sql server to the oracle db just did not commit although i explicitely commited in sql server management studio. Yes all that was missing was a commit. Having the statement run as a step in a scheduled job on the sql server with a commit never gave any problems. And the problem running the query in the oracle side AFTER running it first on the sql server side was causing the oracle side to run forever because the transaction was not commited. Again sorry for my question and confusion. Thanks for your comments an help.Cheers – quebonito Jul 17 '21 at 10:35

0 Answers0