Search code examples
sap-iq

Why is this Sybase IQ Update Statment So Slow?


I have one table (Table1) with some info and a string ID

I have another table (Table2) with some more info and a similar string ID (it is missing an extra char in the middle).

I was originally joining the tables on

t2.StringID = substring(t1.StringID,0,2)+substring(t1.StringID,4,7)

But that was too slow, so I decided to create a new column on Table1 which is already mapped to the PrimaryID of Table2, and then index that col.

So, to update that new column I do this:

select distinct PrimaryID, 
                substring(t2.StringID,0,2)+
                substring(t2.StringID,4,7)) as StringIDFixed
into #temp
from Table2 t2

update Table1 tl
set t1.T2PrimaryID = isnull(t.PrimaryID, 0)
from Table1 t11, #temp t
where t11.StringID = t.StringIDFixed
and t1.T2PrimaryID is null  

It creates the temp table in a few seconds, but the update has been running for 25 minutes now, and I dont know if it will even ever finish.

Table 1 has 45MM rows, Table 2 has 1.5MM

I know that's a chunky amount of data, but still, i feel like this shouldnt be that hard.

It's Sybase IQ 12.7

Any ideas?

Thanks.


Solution

  • Created an index on the temp table which took a few seconds, and then re ran the same update which then only took 7 seconds.

    create index idx_temp_temp on #temp (StringIDFixed)
    

    I hate Sybase.