Skip to content

Temporary table performance #712

Description

@swidz

Hi,

I have tired using temp tables during data cleanup process.

First load some ids to temp table and use the temp table in exists clause to filter out data to be deleted
I realize that this process might be slow because temp data are stored on the client, so the EXISTS command is actually processing one row at a time. But in some cases this seems the only way to go

But I have also noticed that the process of inserting into temp table is not performing:


DROP TABLE IF EXISTS #DELCUST
CREATE TABLE #DELCUST (
    GAS_ACCOUNTID UNIQUEIDENTIFIER
);	

INSERT INTO #DELCUST (GAS_ACCOUNTID)
SELECT TOP [N] T1.gas_accountid FROM gas_account T1

I have tested for [N] = 1, 10, 100, 1000, 10000

1,10,100,1000 works ok
with 10000 the query never ends (I was not so patient to wait till the end ;) )
When I press stop query execution the cancelling is also never ending.

  1. Can insert performance be improved?
  2. What is the current limit to work with temp tables?

My use case is as following:


DROP TABLE IF EXISTS #DELCUST
	CREATE TABLE #DELCUST (
		GAS_ACCOUNTID UNIQUEIDENTIFIER
	);	

INSERT INTO #DELCUST (GAS_ACCOUNTID)
SELECT /* TOP 10 */ T1.gas_accountid FROM gas_account T1
WHERE 1 = 1 /* filter condition */

-- Delete tables related to account
-- finally delete account records

DELETE T1 FROM gas_account T1
WHERE EXISTS (SELECT 1 FROM #DELCUST T2 WHERE T1.gas_accountid = T2.gas_accountid)

Best regards,
Sebastian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions