Previous Thread
Next Thread
Print Thread
Hop To
#170712 12/20/2006 4:36 PM
Joined: Dec 2006
Posts: 7
D
stranger
stranger
D Offline
Joined: Dec 2006
Posts: 7
I'm importing a few tens of thousands of topics with something like 1.3 million posts into ubb7, and it gets really slow as I get upwards of 30k topics. It looks to me like this is because sorting on b_number and using a LIMIT n, 21 to get the next block of 20 topics requires MySQL to filter and sort the entire list of n-1 topics to get to the nth one.

Wouldn't it be faster to pass the last-processed topic number instead of ordinal, and change the query to something like:

select * from ${PREFIX}Posts WHERE B_Topic = 1 AND B_Number > [the last one processed] ORDER BY B_Number ASC LIMIT 20

That runs very much faster on my test system.

Thanks,

-D

Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
That very well may be a better route to go. I'll work on making that change as soon as I get a chance.

Joined: Dec 2006
Posts: 7
D
stranger
stranger
D Offline
Joined: Dec 2006
Posts: 7
Hi Rick,

Here's the patch I applied to the importer script. It hasn't seen any real testing yet, but I figured it might be a good start. I also added an index on w3t_Posts (B_Topic, B_Number) which lets MySQL scan far fewer index rows to find topics, and in fact gets faster the closer it gets to the end.

Hope this proves useful.

-D

62a63,64
> $startPostID = get_input("startPostID","get","int");
> if(strlen($startPostID) < 1) { $startPostID = 0;}
771c773
< global $html, $dbh, $cgi, $dbh65, $dbprefix, $start, $config, $topics, $site_id, $graemlins;
---
> global $html, $dbh, $cgi, $dbh65, $dbprefix, $start, $config, $topics, $site_id, $graemlins, $startPostID;
788c790
< $limit = "$start,21";
---
> $limit = "21";
792a795
> AND B_Number > $startPostID
795a799
> //echo "<pre> $query</pre><br/><br/>\n";
827a832,834
>
> // remember this topic's ID
> $endID = $topic_data['B_Number'];
1083c1090
< transition("Continuing...", "threads_import.php?ubb=posts&start=$end", 1);
---
> transition("Continuing...", "threads_import.php?ubb=posts&start=$end&startPostID=$endID", 1);


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
DB error - Need help
by Pilgrim - 06/21/2025 5:52 PM
Honestly Disappointed in v8
by - 04/22/2025 2:21 PM
Who's Online Now
0 members (), 128 guests, and 346 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 20250209)