Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^6: CGI Program To Delete Old Data From MySQL Table?

by Jenda (Abbot)
on Oct 02, 2013 at 09:03 UTC ( #1056588=note: print w/ replies, xml ) Need Help??


in reply to Re^5: CGI Program To Delete Old Data From MySQL Table?
in thread CGI Program To Delete Old Data From MySQL Table?

If the table has 60 rows, then any plan and any query will do. I was talking about one 61th of rows, not a single row in the whole of total 61 rows. If the table needs to be periodically cleared of old rows, it probably grows quicker than one row a day.

Clustered indexes do have something to do with the thing. If you use a non-clustered index, then the index basically only contains references to the rows. Therefore for the index to be beneficial to the query execution, the number of selected rows has to be smaller compared to the total number of rows, than for a clustered index. Though with a delete it's probably a little different at least with MSSQL because deleting a whole range of rows means a fairly big change to the tree ad if the table is wide enough ...

I just tested it on MSSQL with a 600 row table (fairly wide) and could not get it to stop using even the nonclustered index even when the condition was expected to select 98% rows. Not even with a 10000 rows table (same width, the table was created by a SELECT TOP xxx FROM a real table).

I guess whoever ends up doing the actual job will need to test it out and find out what works best in this particular situation. In either case I would recommend writing queries so that the server may decide to use an index. No matter whether the index exists at the moment or not. Unless of course it means you have to bend backwards to write it like that.

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re^6: CGI Program To Delete Old Data From MySQL Table?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056588]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-12-22 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls