without knowledge of the database, this is impossible to comment on, but common causes would include:
- a missing index on the column being used to filter (or an unusable index - perhaps due to
varchar
vs nvarchar
, etc)
- blocking due to conflicting operations
- the existence of triggers performing an unbounded amount of additional hidden work
Since the queries appear to be expecting a single RegisteredCustomers
record, you can possibly reduce some overhead by capturing the located Id
into a local variable at the start, and using that local in all three deletes, but this isn't a magic wand:
declare @id int = (
select Id from RegisteredCustomers where Email = '[email protected]');
delete from CustomerRoles where RegisteredCustomerId = @id;
delete from SellerInfos where RegisteredCustomerId = @id;
delete from RegisteredCustomers where Id = @id;
Most likely, though, you'll need to actually investigate what is happening (look at blocks, look at the query plan, look at the IO stats, look at the indexing etc).
If there are lots of foreign keys on the tables, and those foreign keys are poorly indexed, it can take non-trivial amounts of time to perform deletes simply because it has to do a lot of work to ensure that the deletes don't violate referential integrity. In some cases, it is preferable to perform a logical delete rather than a physical delete, to avoid this work - i.e. have a column that signifies deletion, and just do an update ... set DeletionDate = GETUTCDATE() ... where ...
rather than a delete
(but: you need to remember for filter by this column in your queries).