Home arrow Forum Mysql load
  Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 01:45:23 AM
Home New Posts Search Calendar


Login with username, password and session length
+  Joomla Forum
|-+  Joomla Hacks
| |-+  Joomla-SMF Forum Support
| | |-+  Joomla-SMF 1.0.x (Moderators: -Wolverine, kai920)
| | | |-+  Mysql load
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 [2] Go Down Print
Author Topic: Mysql load  (Read 4286 times)
Editor (cowboy)
Administrator
Joomla Guru
*****

Karma: +86/-23
Offline Offline

Posts: 1144



View Profile WWW
Re: Mysql load
« Reply #15 on: October 10, 2005, 02:22:19 PM »

I'm at work  Sad. I'll try to work on it when I get a chance.

My previous reply with various SQL samples are close for your fix.
Logged
Gandalf
Joomla Master
***

Karma: +4/-0
Offline Offline

Posts: 131



View Profile WWW
Re: Mysql load
« Reply #16 on: October 10, 2005, 02:24:04 PM »

oh okay man no problem... i'll try myself to fix it, and if i could i post the modified function, if i didn't post then i couldn't fix it and need your help....

Thanks man...
Logged
Gandalf
Joomla Master
***

Karma: +4/-0
Offline Offline

Posts: 131



View Profile WWW
Re: Mysql load
« Reply #17 on: October 11, 2005, 02:58:37 AM »

I worked on it last night and i discovered something wrong within your function, in fact when you have used OR it makes the function too costly for Mysql.. here's what i've discovered

if i use
Code:
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation, smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM mos_users jos
RIGHT JOIN smf_members smf ON jos.username = smf.memberName
WHERE jos.username = 'test_functions_smf'
OR smf.memberName = 'test_functions_smf'
LIMIT 1

i will get the results
Code:
name  username  email  registerDate  block  password  activation  memberName  realName  passwd  emailAddress  dateRegistered  is_activated  validation_code
test_functions_smf test_functions_smf test_functions_smf@siemens-mobiles.org 2005-10-11 08:08:04 0 ae2b1fca515949e5d54fb22b8ed95575   test_functions_smf test_functions_smf 28b4bb3f81f3c6682fc4f77c0a52091dcb82f17e test_functions_smf@siemens-mobiles.org 1129010884 1

and in "explain sql" i will have:
Code:
table  type  possible_keys  key  key_len  ref  rows  Extra
smf ALL memberName NULL NULL NULL 7187
jos ALL NULL NULL NULL NULL 7189 Using where


But if i use
Code:
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation,
smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM mos_users jos
RIGHT JOIN smf_members smf ON jos.username = smf.memberName
WHERE smf.memberName = 'test_functions_smf'
LIMIT 1

i will get the results
Code:
name  username  email  registerDate  block  password  activation  memberName  realName  passwd  emailAddress  dateRegistered  is_activated  validation_code
test_functions_smf test_functions_smf test_functions_smf@siemens-mobiles.org 2005-10-11 08:08:04 0 ae2b1fca515949e5d54fb22b8ed95575   test_functions_smf test_functions_smf 28b4bb3f81f3c6682fc4f77c0a52091dcb82f17e test_functions_smf@siemens-mobiles.org 1129010884 1

but i'll have in explain sql
Code:
table  type  possible_keys  key  key_len  ref  rows  Extra
smf ref memberName memberName 30 const 3 Using where
jos ALL NULL NULL NULL NULL 7189

So as you can see, not using OR will invoke much less rows to compare because your one is comparing 7000+ rows together and it takes much time, but this one will compare 7000+ to 3 rows which is much much less...

anyway my function looks like this now:
Code:
function isValidUser(&$row, $username, $password) {
global $database, $smf_prefix;

//try first with MOS
$sql = "
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation,
smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM #__users jos
LEFT JOIN {$smf_prefix}members smf ON jos.username = smf.memberName
WHERE jos.username = '$username'
LIMIT 1
";

$database->setQuery($sql);
$database->loadObject( $row );
if ($row != null) {
$mos = ($row->password == md5($password));
$smf = ($row->passwd == sha1(strtolower($username) . $password));
if (!$mos && !$smf)
return 0;
if ($mos && $smf) {
if (!$row->block && $row->is_activated) return 1;
if ($row->block && !$row->is_activated) return 4;
return 5;
}
if ($mos)
return 2;
if ($smf)
return 3;

}

//try with SMF
$sql = "
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation,
smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM #__users jos
RIGHT JOIN {$smf_prefix}members smf ON jos.username = smf.memberName
WHERE smf.memberName = '$username'
LIMIT 1
";
$database->setQuery($sql);
$database->loadObject( $row );
if ($row != null) {
$mos = ($row->password == md5($password));
$smf = ($row->passwd == sha1(strtolower($username) . $password));
if (!$mos && !$smf)
return 0;
if ($mos && $smf) {
if (!$row->block && $row->is_activated) return 1;
if ($row->block && !$row->is_activated) return 4;
return 5;
}
if ($mos)
return 2;
if ($smf)
return 3;
}
}


I confirm that it's much much better to use it this way, but i want you to confirm that it does the exact same work as yours so my function will be good to use it

Best Regards,
Gandalf
Logged
Editor (cowboy)
Administrator
Joomla Guru
*****

Karma: +86/-23
Offline Offline

Posts: 1144



View Profile WWW
Re: Mysql load
« Reply #18 on: October 11, 2005, 11:15:18 AM »

Gandalf,

So the 3rd sample sql is the answer. I don't know why I left that OR there. It's actually useless. You actually optimized the sql.

Well, you did a very good job on this! It's really helpful when users can figure out the problems too.
[1.0.2-done]
« Last Edit: October 12, 2005, 10:44:55 AM by Editor (cowboy) » Logged
Gandalf
Joomla Master
***

Karma: +4/-0
Offline Offline

Posts: 131



View Profile WWW
Re: Mysql load
« Reply #19 on: October 11, 2005, 01:35:07 PM »

I'm glad that i helped man, after all it's a project where everyone must participate to make it very good for our own benefit...

so thank you for the time you give everyone on this project Cheesy
Logged
Pages: 1 [2] Go Up Print 
« previous next »
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Joomla Forum | Powered by SMF 1.1 RC1.
© 2001-2005, Lewis Media. All Rights Reserved.
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!

Joomla Hacks is a Joomla Components, Joomla Modules, Joomla Templates, & Joomla Mambots resource portal. None of the text or images in this public website may be copied without the expressed written consent of the authors. Copyright 2005 by JoomlaHacks.com. Powered by Joomla. All rights reserved.
Terms of Use
Joomla Hacks



Joomla Hacks
German Lang French Lang Italian Lang Spanish Lang Japanese Lang Chinese Lang
Search Contact About Advertise Blogs Topsites Submit News Register Login