Back story i have a table that stores cached times, and currently has about 1m rows. And when i update the table with new versions of the cached items i need to delete the old cached items ( About 3k items ). Its not critical that these items are deteted right away but i would prefere it, as when clients get out cached items i would like them to get the newest version.
But the deleting is still "to" slow taking several seconds making the end user wait, is there any way to make this go faster? Atm im doing a simple sql
DELETE FROM cache where cache_event_id = X
My question becomes: Can i make the query go faster ( I expect the cache table only to grow in size, so this problem will get worse )? Should i make the delete sql run its own thread, and live with the fact that users may old items for a little while?
Pr request the rest of the info for the table.
CREATE TABLE [dbo].[cache](
[cache_id] [int] IDENTITY(1,1) NOT NULL,
[cache_name] [nchar](128) NOT NULL,
[cache_event_id] [int] NOT NULL,
[cache_encounter_id] [int] NOT NULL,
[cache_type_id] [tinyint] NOT NULL,
[cache_creation_date] [datetime] NOT NULL,
[cache_data] [varbinary](max) NOT NULL
) ON [PRIMARY]
All index are created by the sql server profiler, it seems like i need to manualy delete old index Index 1:
CREATE NONCLUSTERED INDEX [_dta_index_cache_6_366624349__K2_K3_K5_K4_7] ON [dbo]. [cache]
(
[cache_name] ASC,
[cache_event_id] ASC,
[cache_type_id] ASC,
[cache_encounter_id] ASC
)
INCLUDE ( [cache_data]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Index 2: // Might actualy not be in use
CREATE NONCLUSTERED INDEX [_dta_index_cache_6_366624349__K5_1_2_3_4_6_7] ON [dbo].[cache]
(
[cache_type_id] ASC
)
INCLUDE ( [cache_id],
[cache_name],
[cache_event_id],
[cache_encounter_id],
[cache_creation_date],
[cache_data]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Index 3 ( I assume this one is usen deleting )
CREATE NONCLUSTERED INDEX [_dta_index_cache_6_366624349__K3] ON [dbo].[cache]
(
[cache_event_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Data is insert to the table via BulkCopy class
Data is fetched out ( This is the most critical part )
SqlCommand cmd = new SqlCommand("GetPageCache", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@event_id", EventID); // int
cmd.Parameters.AddWithValue("@encounter_id", EncounterID); // int
cmd.Parameters.AddWithValue("@type_id", (int)CacheType); //int
cmd.Parameters.AddWithValue("@cachename", CacheName); // Required in some cases, but 90% this is just a fallback