![]() |
Speed up my Query please
I have a quite large query to perform towards the vB database post table.
I want to pull out the last 10 posts, but I do not want to include certain threadid's and forumid's. Right now the query is like this: mysql_query("SELECT * FROM post WHERE threadid NOT IN($excludethreadid) AND forumid NOT IN($excludeforumid) LIMIT 10"); $excludethreadid is set with a bunch of threadids (into the hundreds, maybe toward a thousand). $excludeforumid has a bunch of forumids not to be included in the query result. Thing is that this query, when I have around 600+ users, is taking an extremely large amount of the CPU power and queing up requests and bogging down the whole system. Is there a better way than my version above to query the post table and exclude certain preset id's in the two fields threadid and forumid? Would appreciate help in this matter. |
I suppose that in the real query you also have a 'ORDER BY dateline DESC'?
You could try to add indexes to both forumid & dateline to speed things up. |
Just curious: post doesn't have a forumid column?
|
Nope. It doesn't. Which is a royal pain in the patoot at times.
|
Quote:
KirbyDE, yep. It is has a forumid field. Why? Quote:
But are you sure? Because this query is really annoying me to the extent that I think I'm gonna remove it. But my users really want it because it helps users not having to browse through the forum all the time. Instead just visit the first page of my site. btw, I guess you all understand that this is a vBulletin database that I am querying. The number of posts is up into the millions. |
Normally it does not, that's why I asked.
|
Swedie, what about caching? If it's such a large database, maybe you could create a cache for the last 10 posts. When somebody makes a new post, the cache is updated.
Amy |
Quote:
Alright. To be sure I am quoting my own query right I'll post up the same verson i got online right now PHP Code:
I am querying the thread table. Quote:
Currently I am caching the result in a .txt file on the server. And the script only runs every 30 seconds. |
PHP Code:
|
Just thinking aloud... but what about putting in a dateline restriction that restricts the data to within the last week (that is assuming that you would have more than 20 within a week)?
I honestly dont know if that would help - just thinking aloud. |
Quote:
Btw, totally off-topic, is this automerge thingy that has happened for me a couple of times. Is this a new feature in vb3.0.8? I have vb3.0.3 right now. Quote:
|
Nope. It's a Hack by Xenon :)
|
What about the order of the WHERE clause? For example, the first post has NOT IN($excludethreadid) AND forumid NOT IN($excludeforumid) but $excludethreadid is likely bigger than $excludeforumid, so does order matter here?
|
Quote:
Quote:
I have a limit of 20 in the first query to ensure that the total after the exceptions has been made that i still have atleast 10 left. |
I am not sure if order does matter. But if mySQL is smart (I expect it is) it should optimize the query itself to perform bolean shortcut tests as fast as possible.
|
Quote:
Quote:
Maybe (not sure!) better PHP Code:
|
PHP Code:
I suggest you just put back the threadid in the WHERE clause. Then add indexes on all (on forumid, on threadid & on lastpost) columns used in a WHERE or ORDER BY clause. This could speed up things a lot. For threadid and forumid, you can use unique indexes. |
Yes, those are all possible Values for sticky and visible.
Depending on the mySQL Version, this is necessary to convince the optimizer to use the Indexes. Take a look at search.php, it does the same. https://vborg.vbsupport.ru/showthread.php?t=66578 |
All times are GMT. The time now is 02:49 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|