View Full Version : DB timing out?
When I submit this query, it is just returning a blank white page.
SELECT * FROM `leads`
WHERE (`id` != "31769629-4a63-83b2-de31-49b3a5e72271"
OR `id` != "162541ac-8842-86c9-6fa8-49af50d437e6"
OR `id` != "df61cc92-4af1-6f22-6aa3-4a4a9fd293e6")
Except it is MUCH bigger... I am trying to pull all IDs from a DB of over 22,000 records EXCEPT about 3000 of them.
Any ideas how I can do that without the DB timing out like that?
slapshot_oi
Jul 21, 2009, 08:01 PM
SELECT *'s pull a lot of data and is slow, especially with MySQL. I wrote a PHP webapp using MSSQL, and working on one now with MySQL, and MySQL is dog slow.
Anyway, try selecting just one field.
Or, you could selecting one-third of the table and union that with the two-thirds and final third.
DrJ
Jul 22, 2009, 08:59 AM
I thought of trying that.. but I don't know how I would sift out just a third, then grab another third without grabbing any of the same records, then the final third without grab anymore of the same records.
The only way I know how to do this is using a != and that seams to be what is causing it all to time out.
The temporary solution I had to do was pull the whole table... then use Excel to find the matching ID#s from another tab and marking the original list. Then sorting and deleting based on that marking.
With 20,000 records though, it was a pain in my @ss...
slapshot_oi
Jul 22, 2009, 09:23 AM
I thought of trying that.. but I dont know how I would sift out just a third, then grab another third without grabbing any of the same records, then the final third without grab anymore of the same records.
I didn't realize what I posted. I wrote one thing but was thinking another. I guess this would be how to do it, not sure if it'll run but it looks okay.
SELECT *
FROM table_a
WHERE (`id` != "31769629-4a63-83b2-de31-49b3a5e72271"
OR `id` != "162541ac-8842-86c9-6fa8-49af50d437e6"
OR `id` != "df61cc92-4af1-6f22-6aa3-4a4a9fd293e6")
LIMIT 0, (SELECT COUNT(*) * 1/3 FROM table_a)
UNION
SELECT *
FROM table_a
WHERE (`id` != "31769629-4a63-83b2-de31-49b3a5e72271"
OR `id` != "162541ac-8842-86c9-6fa8-49af50d437e6"
OR `id` != "df61cc92-4af1-6f22-6aa3-4a4a9fd293e6")
LIMIT (SELECT COUNT(*) * 1/3 FROM table_a), (SELECT COUNT(*) * 2/3 FROM table_a)
UNION
SELECT *
FROM table_a
WHERE (`id` != "31769629-4a63-83b2-de31-49b3a5e72271"
OR `id` != "162541ac-8842-86c9-6fa8-49af50d437e6"
OR `id` != "df61cc92-4af1-6f22-6aa3-4a4a9fd293e6")
LIMIT (SELECT COUNT(*) * 2/3 FROM table_a), (SELECT COUNT(*) FROM table_a)
slapshot_oi
Jul 22, 2009, 12:17 PM
Wait a second, are you trying to retrieve all records but those three? If that's the case, use AND instead of OR.