473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

query speed

111 100+
Hi

I have a mysql query which seems to execute slowly.
I was wondering if there was a way to speed it up a bit.

the query is;
Expand|Select|Wrap|Line Numbers
  1. select count(*) as emailCount from mailing_list where user like 'joel@bloggs.com' and list_id = '47'
this table has a primary key called 'email_id'
so I was wondering if

Expand|Select|Wrap|Line Numbers
  1. select count(email_id) as emailCount from mailing_list where user like 'joel@bloggs.com' and list_id = '47'
would execute faster, but it still seems to be roughly the same amount of time.


I have about 1 million records in this table, and the query takes about 2 seconds to execute. I would like to reduce this time as much as possible, as i have a few other queries that get executed later on in my coding. therefore the overall speed will seems even slower.

thanks in advance
Apr 17 '08 #1
4 1561
code green
1,726 Expert 1GB
Replace the LIKE with equals (=) if you do not really need the LIKE.
And remove the quotes from numeric values
Expand|Select|Wrap|Line Numbers
  1. select count(email_id) as emailCount from mailing_list where user = 'joel@bloggs.com' and list_id = 47
Apr 17 '08 #2
mwasif
802 Expert 512MB
Creating indexes on user and list_id will make the query much faster. You can use EXPLAIN to measure the query performance.
Apr 17 '08 #3
nitinpatel1117
111 100+
Hi code green,

thanks for that,

i have two more questions though.

firstly
I've read that having indexes in the where part of the sql query will increase speed further. i will mainly be doing selects than inserts, so this seems logical. However there is one thing that i don't quite get. Using my above example can i use 'user' field or 'list_id' field as an index, these fields are not unique, so will indexes still work or bring about an improvement in speed.

Second
Does count(email_id) execute alot faster than count(*), if so its probably worth me doing this for all my queries where i may using this.

thanks
Apr 17 '08 #4
nitinpatel1117
111 100+
I checked my table type, it is InnoDB.

If I were to change this to MyISAM, would this have any adverse effects on my table, and in particluar the data stored in the table?
Apr 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wouter | last post by:
Hi, I was wandering. Does the query speed also depend on the colums that you don't use in the query (so not in the where and not in the select part). I have a lange unused backup field in...
9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
5
by: sql-db2-dba | last post by:
We have DB2 UDB v8.1 fixpak3 on AIX 5. Production and Development configuarations (at least for DB2) are identical albeit production is a 2-way server while development has only one processor....
11
by: 73blazer | last post by:
We are migrating a customer from Version 7.1 FP3, to Version 8.2 (8.1 FP8). For the most part, things are faster, but there is one query that is much much slower, and it is a query that is used all...
3
by: Not Me | last post by:
Hi, In the past I seem to have been able to speed up queries by making them a join rather than ... not a join :o) An example would be select * from x where a in (select a from y) would...
3
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while...
4
by: Miks | last post by:
The database scheme consists of four relations: Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price) Laptop(code, model, speed, ram, hd, screen, price) Printer(code, model,...
5
by: - | last post by:
I have only 1m records in my database running on a laptop of speed 1.6GHz, memory 512MB ram, and Toshiba MK8032GAX hard disk. I use 'LIMIT x,10' for the query to utilise record paging. When the...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
3
by: binita2908 | last post by:
Hi guys , I am quite a baby to sql , pls help me out in this . My database scheme consists of four relations: Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.