php forum
php mysql forum
php mysql smarty
 
Topic Options
#216768 - 05/16/02 01:11 PM Pal 4.3 - Speeding up a bit
SCybak Offline
Newbie

Registered: 05/03/02
Posts: 18
Dave, your addon is amazing, however, i've ripped through it and have sped up a few queries. The biggest problem i've seen so far is the query that assembles the group where clause statement.<br /><br />You assemble a where clause formated (B_Board = 'BoardName' OR B_Board = 'wee' OR ....)<br /><br />I tested a different approach which returns<br /><br />B_Board IN ('Name1', 'Name2', 'Name3')<br /><br />This approach seems to strip some time from all of the queries that use it .. i'm unsure if it has to do with what i found in the mysql documentation:<br /><br />http://www.mysql.com/documentation/mysql/bychapter/manual_MySQL_Optimization.html#MySQL_indexes<br /><blockquote><font class="small">In reply to:</font><hr><br /><br />These WHERE clauses do NOT use indexes: <br /><br />... WHERE index_part2=1 AND index_part3=2 /* index_part_1 is not used */<br />... WHERE index=1 OR A=10 /* Index is not used in both AND parts */<br />... WHERE index_part1=1 OR index_part2=10 /* No index spans all rows */<br /><br /><br /><hr></blockquote><br /><br />In any event, the speed difference is noticeable. HTH

Top
#216769 - 05/17/02 06:40 PM Re: Pal 4.3 - Speeding up a bit [Re: numbnutz]
JustDave Offline
That 70's Guy

Registered: 06/24/01
Posts: 4097
Ok I am no pro at this so let me see if I can understand you. Are you getting rid of the (B_Board = 'BoardName' OR B_Board = 'wee' OR ....) ?<br /><br />If so this query is what keeps users from seeing board information that they do not have group access to.<br /><br />Could you show me exactly the reformatting you have done to specify what boards a user has access to view when retrieving information? I would really appreciate this. <img src="/forum/images/icons/smile.gif" alt="" /> I would love to speed things up but I don't want to lose having information displayed according to group access. I know I'm not the only one out there with private boards. <img src="/forum/images/icons/wink.gif" alt="" /><br /><br />
_________________________
~Dave
ChattersOnline.com

Top
#216770 - 05/19/02 01:45 PM Re: Pal 4.3 - Speeding up a bit [Re: sjsaunders]
SCybak Offline
Newbie

Registered: 05/03/02
Posts: 18
Here's a sample of what's it's basically done . The first part is your original that pulls the read perms into group array, i just slightly modify how it grabs the board numbers and stores them as the end where clause:<br /><br /><br /> $Grouparray = split("-",$user['U_Groups']);<br /><br /> $gsize = sizeof($Grouparray);<br /> $g = 0;<br /> for ($i=0; $i<=$gsize; $i++) {<br /> if (!ereg("^[0-9]",$Grouparray[$i])) { continue; }<br /> $g++;<br /> if ($g > 1) {<br /> $groupquery .= " OR ";<br /> }<br /> $groupquery .= "Bo_Read_Perm LIKE '%-$Grouparray[$i]-%'";<br /> }<br /> }<br /><br /> $Sql = "SELECT Bo_Keyword<br /> FROM w3t_Boards<br /> WHERE ($groupquery)<br /> ";<br /> $groupwhere = "";<br /><br /> $Qry = mysql_unbuffered_query($Sql);<br /><br /> while ($Rst = mysql_fetch_row($Qry)) {<br /> $groupwhere .= ", '$Rst[0]'";<br /> }<br /><br /> $groupwhere = "B_Board IN (" . substr($groupwhere, 1, strlen($groupwhere)) . ")";<br /><br />The permsisions are still set and this would be the only portion of code you'd have to change (it would blend right into your existing queries)<br /><br />Hopefully that illustrates my point a little better

Top
#216771 - 05/19/02 04:40 PM Re: Pal 4.3 - Speeding up a bit [Re: numbnutz]
JustDave Offline
That 70's Guy

Registered: 06/24/01
Posts: 4097
Thanks bunches for the code illustration <img src="/forum/images/icons/smile.gif" alt="" /><br /><br />It makes sense to me now... lol I'll make the changes for the next release and thanks again. <img src="/forum/images/icons/smile.gif" alt="" />
_________________________
~Dave
ChattersOnline.com

Top
#216772 - 05/19/02 08:27 PM Re: Pal 4.3 - Speeding up a bit [Re: numbnutz]
JustDave Offline
That 70's Guy

Registered: 06/24/01
Posts: 4097
I was looking this over and was thinking that it adds another query but then I realized that I am pulling the boards keywords out already for other queries so it is a matter of fomatting.<br /><br />In the 4.3 index page you will see this...<br /><pre><font class="small">code:</font><hr><br /> $Grouparray = split("-",$Groups);<br /> $gsize = sizeof($Grouparray);<br /> $groupquery = "AND (";<br /> $g = 0;<br /> for ($i=0; $i<$gsize;$i++) {<br /> if (!ereg("^[0-9]",$Grouparray[$i])) { continue; };<br /> $g++;<br /> if ($g > 1) {<br /> $groupquery .= " OR ";<br /> }<br /> $groupquery .= "Bo_Read_Perm LIKE '%-$Grouparray[$i]-%'"; <br /> }<br /> $groupquery .= ")";<br /><br /> $query = "<br /> SELECT Bo_Keyword,Bo_Title<br /> FROM w3t_Boards<br /> WHERE Bo_Keyword != ''<br /> $groupquery<br /> ";<br /> $sth = $dbh -> do_query($query);<br /> $boardquery = "AND (";<br /> $boardquery2 = "AND (";<br /> $g = 0;<br /> while (list ($BKeyword,$BTitle) = $dbh -> fetch_array($sth)) {<br /> $palBkeyword[$g] = "$BKeyword";<br /> $palBtitle[$g] = "$BTitle";<br /> $g++;<br /> if ($g > 1) {<br /> $boardquery .= " OR ";<br /> $boardquery2 .= " OR ";<br /> }<br /> $boardquery .= "B_Board = '$BKeyword'";<br /> $boardquery2 .= "w3t_Posts.B_Board = '$BKeyword'"; <br /> }<br /> $dbh -> finish_sth($sth);<br /> $boardquery .= ")";<br /> $boardquery2 .= ")";<br /></pre><hr><br /><br />The above code would be changed to this?....<br /><br /><pre><font class="small">code:</font><hr><br /> $Grouparray = split("-",$Groups);<br /> $gsize = sizeof($Grouparray);<br /> $groupquery = "AND (";<br /> $g = 0;<br /> for ($i=0; $i<$gsize;$i++) {<br /> if (!ereg("^[0-9]",$Grouparray[$i])) { continue; };<br /> $g++;<br /> if ($g > 1) {<br /> $groupquery .= " OR ";<br /> }<br /> $groupquery .= "Bo_Read_Perm LIKE '%-$Grouparray[$i]-%'"; <br /> }<br /> $groupquery .= ")";<br /><br /> $query = "<br /> SELECT Bo_Keyword,Bo_Title<br /> FROM w3t_Boards<br /> WHERE Bo_Keyword != ''<br /> $groupquery<br /> ";<br /> $sth = $dbh -> do_query($query);<br /> $boardquery = "B_Board IN (";<br /> $boardquery2 = "AND (";<br /> $g = 0;<br /> while (list ($BKeyword,$BTitle) = $dbh -> fetch_array($sth)) {<br /> $palBkeyword[$g] = "$BKeyword";<br /> $palBtitle[$g] = "$BTitle";<br /> $g++;<br /> if ($g > 1) {<br /> $boardquery .= ",'$BKeyword'";<br /><br /> }<br /> else {<br /> $boardquery .= "'$BKeyword'";<br /> }<br /> if ($g > 1) {<br /> $boardquery2 .= " OR ";<br /> }<br /> $boardquery .= "B_Board = '$BKeyword'";<br /> $boardquery2 .= "w3t_Posts.B_Board = '$BKeyword'"; <br /> }<br /> $dbh -> finish_sth($sth);<br /> $boardquery .= ")";<br /> $boardquery2 .= ")";<br /></pre><hr> <br /><br />After making the changes to the query formatting it produced many sql errors. Is this simular to what you have done as far as the above code is concerned?<br /><br />Also, just wanted to note that in 5.0(coming soon, well eventualy) the $boardquery2 is no longer needed/present. <img src="/forum/images/icons/smile.gif" alt="" />
_________________________
~Dave
ChattersOnline.com

Top
#216773 - 05/20/02 11:03 AM Re: Pal 4.3 - Speeding up a bit [Re: sjsaunders]
SCybak Offline
Newbie

Registered: 05/03/02
Posts: 18
<pre><font class="small">code:</font><hr> <br /> $Groups = $user['U_Groups']; <br /> if (!$Groups) { <br /> $Groups = "-4-"; <br /> } <br /> <br /> $Grouparray = split("-",$Groups); <br /> $gsize = sizeof($Grouparray); <br /> $groupquery = "AND ("; <br /> $g = 0; <br /> for ($i=0; $i<$gsize;$i++) { <br /> if (!ereg("^[0-9]",$Grouparray[$i])) { continue; }; <br /> $g++; <br /> if ($g > 1) { <br /> $groupquery .= " OR "; <br /> } <br /> $groupquery .= "Bo_Read_Perm LIKE '%-$Grouparray[$i]-%'"; <br /> } <br /> $groupquery .= ")"; <br /> <br /> $query = " <br /> SELECT Bo_Keyword,Bo_Title <br /> FROM w3t_Boards <br /> WHERE Bo_Keyword != '' <br /> $groupquery <br /> "; <br /> $sth = $dbh -> do_query($query); <br /> $boardquery = "AND ("; <br /> $boardquery2 = "AND ("; <br /> $g = 0; <br /> while (list ($BKeyword,$BTitle) = $dbh -> fetch_array($sth)) { <br /> $palBkeyword[$g] = "$BKeyword"; <br /> $palBtitle[$g] = "$BTitle"; <br /> $g++; <br /> if ($g > 1) { <br /> $boardquery .= " OR "; <br /> $boardquery2 .= " OR "; <br /> } <br /> $boardquery .= "B_Board = '$BKeyword'"; <br /> $boardquery2 .= "w3t_Posts.B_Board = '$BKeyword'"; <br /> } <br /> $dbh -> finish_sth($sth); <br /> $boardquery .= ")"; <br /> $boardquery2 .= ")"; <br /></pre><hr> <br /> <br />would become <br /> <br /><pre><font class="small">code:</font><hr> <br /> $Groups = $user['U_Groups']; <br /> if (!$Groups) { <br /> $Groups = "-4-"; <br /> } <br /> <br /> $Grouparray = split("-",$Groups); <br /> $gsize = sizeof($Grouparray); <br /> $groupquery = "AND ("; <br /> $g = 0; <br /> for ($i=0; $i<$gsize;$i++) { <br /> if (!ereg("^[0-9]",$Grouparray[$i])) { continue; }; <br /> $g++; <br /> if ($g > 1) { <br /> $groupquery .= " OR "; <br /> } <br /> $groupquery .= "Bo_Read_Perm LIKE '%-$Grouparray[$i]-%'"; <br /> } <br /> $groupquery .= ")"; <br /> <br /> // ------------------------- <br /> // begin modification <br /> <br /> $query = "SELECT Bo_Keyword <br /> FROM w3t_Boards <br /> WHERE ($groupquery) <br /> <br /> $sth = $dbh -> do_query($query); <br /> $boardquery = ""; <br /> while (list ($BKeyword) = $dbh -> fetch_array($sth)) { <br /> $boardquery .= ", '$BKeyword'"; <br /> } <br /> $boardquery = "B_Board IN (" . substr($boardquery, 1, strlen($boardquery)) . ")"; <br /> $boardquery2 = "w3t_Posts.$boardquery"; <br /></pre><hr>


Edited by SCybak (05/20/02 11:04 AM)

Top
#216774 - 05/20/02 12:03 PM Re: Pal 4.3 - Speeding up a bit [Re: numbnutz]
JustDave Offline
That 70's Guy

Registered: 06/24/01
Posts: 4097
I'm still getting errors <img src="/forum/images/icons/frown.gif" alt="" /><br /><br />The 5.0 index page is not completely the same as 4.3 but the code was easy to place into the page. I still get numerous sql errors. Is this ment for a particular mysql version? I'm on an older version.
_________________________
~Dave
ChattersOnline.com

Top
#216775 - 05/20/02 12:11 PM Re: Pal 4.3 - Speeding up a bit [Re: numbnutz]
JustDave Offline
That 70's Guy

Registered: 06/24/01
Posts: 4097
I changed the 5.0 index page to the following and it wouldn't work... maybe I'm missing something... Let me know if you see what I'm doing wrong. <img src="/forum/images/icons/smile.gif" alt="" /><br /><br /><pre><font class="small">code:</font><hr><br /> $boardquery = "";<br /><br /><br /> while (list ($BKeyword,$BTitle,$BWritePerm,$BReplyPerm,$BReadPerm,$BTopicon) = $dbh -> fetch_array($sth)) {<br /><br /> $palBKeyword[$BKeyword] = "$BKeyword";<br /> $palBTitle[$BKeyword] = "$BTitle";<br /> $palBWritePerm[$BKeyword] = "$BWritePerm";<br /> $palBReplyPerm[$BKeyword] = "$BReplyPerm";<br /> $palBReadPerm[$BKeyword] = "$BReadPerm";<br /> $palBTopicon[$BKeyword] = "$BTopicon";<br /><br /><br /><br /> $boardquery .= ", '$BKeyword'";<br /><br /> <br /> }<br /> $dbh -> finish_sth($sth);<br /><br /><br /> $boardquery = "B_Board IN (" . substr($boardquery, 1, strlen($boardquery)) . ")";<br /></pre><hr>
_________________________
~Dave
ChattersOnline.com

Top



Latest Posts
[7.2.1] - Naked shoutbox
by bellaonline
05/05/12 05:00 PM
[7.x] Stop Forum Spam Integration v0.4
by bellaonline
05/05/12 03:53 PM
Shout Box

(Views)Popular Topics
Known public proxy servers 1689885
Integrated Index Page (IIP) 5.3.1 555705
Finished-[6.5.2] Games Arcade Deluxe v1.9 501236
Integrated Index Page (IIP) 5.1.1 415112
TLD Bv2.1 Released - Threads Links Directory 396822
[6.0x] Who's Online 4.0.0 [Finished] 389412
Finished-[6.5.1] Integrated Index Page (IIP) 6.5 330423
Q & A 298663
Slash UBB 266936
[6.3.x] [beta] Hit Hack 2.0 227970
Forum Stats
13621 Members
59 Forums
37191 Topics
295716 Posts

Max Online: 686 @ 06/28/07 07:04 AM

 

 

 
fusionbb message board php hacks