OPERQUERY query about efficiency, or the correct usage

Original: https://blog.csdn.net/u013641136/article/details/50379596

 

Did a project, then you need to create a query by OPERQUERY access ORACLE ORACLE record of DBLINK in a SQLSERVER SQLSERVER and return to the table

ORACLE amount of data in the row about 100W, using insert into T1 (X1, X2, X3) SELECT * FROM OPENQUERY (XXXXX) way, efficiency is very low, especially very often query by the conditions, only to return a few records , it takes tens of minutes, even if changed to insert into T1 (X1, X2, X3) SELECT * FROM OPENQUERY (XXXXX) where xxx is not OK. This is already beyond the scope of the efficiency of slow, but the statement in question.

Later, consider for a moment, because it is regarded as the second slow queries, ORACLE will first query returns all data to OPERQUERY, the conditions to OPERQUERY press inquiries, improve the efficiency of the method is to put OPERQUERY conditions, the conditions are not yet a value, but another temporary table, using a solid way cursor, a temporary table in a recording process variable, as a condition into OPERQUERY performed. Sure enough, no longer appear inquiry three records into SQLSERVER it takes 30 minutes to just 1 second.
Examples of statements:

declare @itemid nvarchar(100)
declare auth_cur cursor for


select item_number


from erp_part_item


open auth_cur


fetch next from auth_cur into @itemid


while (@@fetch_status=0)


  begin
    DECLARE @TSQL varchar(8000)
    SELECT  @TSQL = 'insert into HISTORY_ITEM(ITEM_NUMBER,ITEM_TEMPLATE,ITEM_DESC,ITEM_UOM,UNIT_WEIGHT,ORG,FLAG,inventory) SELECT * FROM OPENQUERY(TO_ERPZS,''SELECT ITEM_NUMBER,ITEM_TYPE,ITEM_DESCRIPTION,PRIMARY_UOM_CODE,UNIT_WEIGHT,ORGANIZATION_CODE,LOT_FLAG,Inventory_Item_Status_Code from APPS.CUX_PDM_ITEMS_BOM_V where item_number =  ''''' + @itemid + ''''''')'
    EXEC (@TSQL)
    fetch next from auth_cur into @itemid
  end


close auth_cur


deallocate auth_cur

 

Guess you like

Origin www.cnblogs.com/tc310/p/11106884.html
Recommended