Previous Thread
Next Thread
Print Thread
Hop To
Joined: Oct 2007
Posts: 531
Likes: 13
Addict
Addict
Joined: Oct 2007
Posts: 531
Likes: 13
Looking at my slow query log, the biggest offender is the search query. It's looking at every single row in the db.
Code
# Time: 2026-07-04T02:02:07.965410Z
# User@Host: ubb[ubb] @ localhost []  Id: 20276792
# Query_time: 5.692897  Lock_time: 0.000002 Rows_sent: 6  Rows_examined: 1051691
SET timestamp=1783130522;
SELECT p.POST_ID
FROM
{$config_POSTS AS p
LEFT JOIN {$config_POSTS AS pp ON p.POST_ID = pp.POST_ID,
{$config_TOPICS AS t
WHERE
p.POST_IS_APPROVED = '1'
AND t.TOPIC_STATUS <> 'M'
AND t.FORUM_ID IN ('1','2','3','4','5','39','7','9','10','11','85','13','14','15','16','17','18','19','20','21','22','91','90','24','26','27','28','29','30','95','33','38','35','36','40','88','45','68','65','54','52','49','55','50','51','53','56','58','60','61','72','89','69','71','73','74','75','76','77','78','81','86','93','92','94')
AND p.TOPIC_ID = t.TOPIC_ID
AND (   (LOWER(p.POST_SUBJECT) LIKE LOWER('%spare lock%') OR LOWER(p.POST_DEFAULT_BODY) LIKE LOWER('%spare lock%'))) 
 
 
 
 
ORDER BY p.POST_POSTED_TIME DESC
LIMIT 400;[/
I offer these as suggestions for improving performance of the forums and not as a criticism.
This query is in dosearch..inc.php on line 548.
The problem is that LIKE '%term%' (with leading wildcard) cannot use normal indexes — so it forces a full table scan
A possible fix is to add a FULLTEXT search index to POST_SUBJECT and POST_DEFAULT_BODY.
E.G.
SQL Query
ALTER TABLE {$config_POSTS 
ADD FULLTEXT idx_search (POST_SUBJECT, POST_DEFAULT_BODY);
You might want to also consider adding similar indexes for POST_IS_APPROVED, POST_POSTED_TIME as well as TOPIC_ID, POST_IS_APPROVED.
SQL Query
-- On POSTS
ALTER TABLE {$config_POSTS ADD INDEX idx_approved_time (POST_IS_APPROVED, POST_POSTED_TIME);
ALTER TABLE {$config_POSTS ADD INDEX idx_topic_approved (TOPIC_ID, POST_IS_APPROVED);

-- On TOPICS
ALTER TABLE {$config_TOPICS ADD INDEX idx_forum_status (FORUM_ID, TOPIC_STATUS);
Then the query would need to use MATCH AGAINST to take advantage of these new indexes.
So, instead of this:
PHP Code
$andquery .= "$andconcat (LOWER(p.POST_SUBJECT) LIKE LOWER('%$word%') ... )" 
You would use someting like this:
PHP Code
$match_terms = "AND MATCH(p.POST_SUBJECT, p.POST_DEFAULT_BODY) AGAINST ('$words_escaped' IN BOOLEAN MODE)"; 
Then, for a full search, you cold use something like this:
PHP Code
$match_terms = "AND MATCH (p.POST_SUBJECT, p.POST_DEFAULT_BODY) AGAINST ('$words_escaped' IN BOOLEAN MODE)"; 

These changes would likely reduce the search query time from almost 6 seconds to under 1 sectond.


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.82 GB
Joined: Jun 2006
Posts: 16,532
Likes: 150
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,532
Likes: 150
Again, could you please stop posting coding suggestions from AI sources (Grok, CloudFlare AI, etc)... AI sources don't have access to the entirety of the code base to make worthwhile suggestions, we have the same tools to run directly on the stock builds without any 3rd party additions to HTML or PHP coding (either added by a user, developer, or 3rd party tools such as CloudFlare which inject HTML into pages); we regularly run the product through our own IDE tools.

UBB.threads has had had FULLINDEX searches for eons, enable it in your Control Panel (see the attachment) if it is a feature that you would like to use.

The reason it's a slow query during a search is because it's trolling through your hundreds of thousands of posts looking for the search query, it only has impact to the user performing the search.

A search will query all "post_default" cells relating to a Post or Topic (and not the "every single row in the db" as your post claims) as they contain the contents of a post.

Examining the query you're posting about:
Code
SELECT p.POST_ID
FROM
{$config_POSTS AS p
LEFT JOIN {$config_POSTS AS pp ON p.POST_ID = pp.POST_ID,
{$config_TOPICS AS t
WHERE
p.POST_IS_APPROVED = '1'
AND t.TOPIC_STATUS <> 'M'
AND t.FORUM_ID IN ('1','2','3','4','5','39','7','9','10','11','85','13','14','15','16','17','18','19','20','21','22','91','90','24','26','27','28','29','30','95','33','38','35','36','40','88','45','68','65','54','52','49','55','50','51','53','56','58','60','61','72','89','69','71','73','74','75','76','77','78','81','86','93','92','94')
AND p.TOPIC_ID = t.TOPIC_ID
AND (   (LOWER(p.POST_SUBJECT) LIKE LOWER('%spare lock%') OR LOWER(p.POST_DEFAULT_BODY) LIKE LOWER('%spare lock%')))
ORDER BY p.POST_POSTED_TIME DESC
LIMIT 400;
- Searches the _POSTS table and the _TOPICS table (left join)
- Where the post is approved, the topic status isn't "M" (Moved, vs C/Closed), that is in any open forum you have
- It then grabs the topic id that matches the post id
- it then searches the subject and default post body fields for your query "spare lock"
- it then orders the results via the last posted time
- and finally we limit the query to 400 results.
Attachments
image.png


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
1 member likes this: isaac
Joined: Oct 2007
Posts: 531
Likes: 13
Addict
Addict
Joined: Oct 2007
Posts: 531
Likes: 13
Originally Posted by Gizmo
Again, could you please stop posting coding suggestions from AI sources (Grok, CloudFlare AI, etc)... AI sources don't have access to the entirety of the code base to make worthwhile suggestions, we have the same tools to run directly on the stock builds without any 3rd party additions to HTML or PHP coding (either added by a user, developer, or 3rd party tools such as CloudFlare which inject HTML into pages); we regularly run the product through our own IDE tools.

UBB.threads has had had FULLINDEX searches for eons, enable it in your Control Panel (see the attachment) if it is a feature that you would like to use.
I obviously was unaware of this. Don't you think it should be the default setting?

Originally Posted by Gizmo
The reason it's a slow query during a search is because it's trolling through your hundreds of thousands of posts looking for the search query, it only has impact to the user performing the search.

A search will query all "post_default" cells relating to a Post or Topic (and not the "every single row in the db" as your post claims) as they contain the contents of a post.
Then why does the query log say Rows_examined: 1051691?


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.82 GB
Joined: Jun 2006
Posts: 16,532
Likes: 150
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,532
Likes: 150
Originally Posted by Baldeagle
I obviously was unaware of this. Don't you think it should be the default setting?
Users on alternative engines such as INNODB or on other SQL servers might have issues with that as a default setting. It can also add to load times on some servers.

Should be so many results per page of a global search of how many results overall... Not to mention however many rows in your posts database that it could match against; I'm not staring at code to look currently.


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Joined: Oct 2007
Posts: 531
Likes: 13
Addict
Addict
Joined: Oct 2007
Posts: 531
Likes: 13
Thank you for that information. I changed our setting to Full Text, and the query dropped to just over 1 second to complete.


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.82 GB

Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
PHP 8 bug in membermanage.tmpl
by phoenix011235 - 09/08/2026 7:47 PM
Are any of these legitmate?
by Baldeagle - 09/06/2026 1:37 PM
After server reboot
by Morgan - 09/02/2026 8:27 AM
8.0.1 Patch Changelog Discussion
by isaac - 11/26/2025 1:34 PM
Who's Online Now
0 members (), 296 guests, and 109 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Ride safe!
Ride safe!
by Morgan, December 7
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260527)