473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with a very slow script

Hi,

I am responsible for a growing website. It is password protected and
we collect data on everyone who logs in. Every month we produce a
report on the trends of users which can result in some very unwieldy
sql statements. We are running MYSQL with SunOne ASP on a Solaris box.

Can anyone help with a way of improving the script - this currently
takes about a minute to complete!

Here is an example of a sql statement:

SELECT Count(stat_logi ns2.Email) AS TOTAL, Users_Details.C ountry FROM
stat_logins2, Users_Details WHERE (WhenLog = '20041015' OR WhenLog <
'20041015') AND (WhenLog = '20040415' OR WhenLog > '20040415') AND
stat_logins2.Em ail LIKE '%company1%' AND stat_logins2.Em ail NOT LIKE
'%company2%' AND stat_logins2.Em ail = Users_Details.E mail GROUP BY
Users_Details.C ountry ORDER BY TOTAL DESC

This is supposed to return a list of total logins by country in
descending order. Below are the structures of the two tables:

stat_logins2 (holds the login data)
CREATE TABLE `stat_logins2` (
`ID` int(10) NOT NULL auto_increment,
`Email` varchar(50) NOT NULL default '',
`Company` varchar(100) NOT NULL default '',
`WhenLog` timestamp(14) NOT NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM;

Users_Details
CREATE TABLE `Users_Details` (
`ID` int(11) NOT NULL auto_increment,
`First_name` varchar(50) NOT NULL default '',
`Last_name` varchar(50) NOT NULL default '',
`Company` varchar(50) NOT NULL default '',
`Email` varchar(50) NOT NULL default '',
`Password` varchar(50) NOT NULL default '',
`Job_title` varchar(50) default NULL,
`Address1` varchar(50) default NULL,
`Address2` varchar(50) default NULL,
`Address3` varchar(50) default NULL,
`Postal_code` varchar(50) default NULL,
`Country` varchar(50) default NULL,
`Line_manager` varchar(50) default NULL,
`Phone` varchar(50) default NULL,
`Commreq` char(3) default NULL,
`Contact` varchar(50) NOT NULL default '',
`Temp_id` varchar(50) NOT NULL default '',
`Dateregistered ` date default '0000-00-00',
`Date_reg` timestamp(14) NOT NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM;

Any help would be most appreciated!
Jul 20 '05 #1
1 1515
Chris Todhunter wrote:
Hi,

I am responsible for a growing website. It is password protected and
we collect data on everyone who logs in. Every month we produce a
report on the trends of users which can result in some very unwieldy
sql statements. We are running MYSQL with SunOne ASP on a Solaris box.

Can anyone help with a way of improving the script - this currently
takes about a minute to complete!

Here is an example of a sql statement:

SELECT Count(stat_logi ns2.Email) AS TOTAL, Users_Details.C ountry FROM
Use COUNT(*) instead of counting the Email field. Since your Email
field is NOT NULL, it's guaranteed to return the same value.
stat_logins2, Users_Details WHERE (WhenLog = '20041015' OR WhenLog <
'20041015') AND (WhenLog = '20040415' OR WhenLog > '20040415')
Is WhenLog indexed?

Also, you're going to run into trouble comparing WhenLog to date values,
if WhenLog contains any non-zero time value. In other words, what if
WhenLog has a value '20040415 10:25:32'?
AND
stat_logins2.Em ail LIKE '%company1%' AND stat_logins2.Em ail NOT LIKE
'%company2%'
LIKE predicates cannot use indexes in this case. If you need to speed
up these comparisons, store the domain portion of the email in separate
column, and compare with a string =. But try indexing your other fields
used in joins and comparisons first; that might solve the speed problem.
AND stat_logins2.Em ail = Users_Details.E mail
I don't know if you have indexed the Email field in your two tables.
This could cause performance penalties to use non-indexed fields in your
join criteria.
GROUP BY Users_Details.C ountry ORDER BY TOTAL DESC


Try indexing Country. Or not -- it's likely that the distribution of
values in that field is 90% a single value, right? In which case an
index doesn't gain you much.

You're ordering by an aggregate field, so there's nothing to index there.

Bill K.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6608
by: yawnmoth | last post by:
using the gethostbyname function seems to noticeably slow down pages. some of the comments in php.net's gethostbyname entry suggest using a version that caches the result, but those versions also only speedup subsequent calls to gethostbyname - the first call is still as slow as ever. so is there anything i can do to speed this up? ...
4
3733
by: Adrian MacNair | last post by:
Hi, I created an image gallery which displays 63 images in a slideshow. The problem is that the show was slow because each image loaded one at a time during the show. No problem right? I just did a preload script. But then the user has to sit for 5 minutes waiting for 63 images to download! My images are about 640x480 and average 100kb. Is...
14
9008
by: jj | last post by:
Is it possible to call a remote php script from within Access? I'm thinking something like: DoCMD... http://www.domain.com/scripts/dataquery.php DoCmd.OpenQuery "update_data", acNormal, acEdit ..... So the PHP script does something on the server database, then when a linked table is viewed within access, the data changes have been made?
59
7461
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when the recordset opens a table. When I write Set rst = db.OpenRecordset("MyTable",dbOpenTable, dbReadOnly) I get an error. I believe it's...
22
3502
by: Albert Oppenheimer | last post by:
I thought my program had to be caught in a loop, and cancelled it through the task manager. It took about one second in Java, but re-implemented in C, it had already run over one minute. I set up a debugger to display the current location each loop and let it run. It did reach completion, but it took 20 minutes. I replaced the calls to...
4
12741
by: Claudio Calboni | last post by:
Hello folks, I'm having some performance issues with the client-side part of my application. Basically, it renders a huge HTML table (about 20'000 cells in my testing scenario), without content. Content is "pushed" from the back via some JS, for the only displayed portion of table. Once the user scrolls, JS updates visible cells with data....
1
2667
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="Dunbarlab9.js" type="text/javascript"></script> <script type="text/javascript">
5
13324
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.