473,804 Members | 3,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the speed hit of "SELECT *" with MySql, as opposed to narrower database calls?


Are there any benchmarks on how much an extra, unneeded VARCHAR, CHAR,
INT, BIGINT, TEXT or MEDIUMTEXT slows down a database call with MySql?
PostGre info would also be useful.

I'm trying to explain to some friends the utility of making database
calls return only needed data.

As an example of what I'm talking about, suppose we had a database
table sort of like this:

table weblogs (
int id,
varchar 255 headline,
text mainContent,
int dateCreated,
varchar 255 author,
varchar 255 navigationText,
char 1 isPrivate
);
Suppose I'm doing a PHP command that get's the headlines and offers a
link to the actual page. What is the speed difference between

SELECT * FROM weblogs

as opposed to

SELECT id, headline FROM weblogs

And is there info out there that gives a general sense of how much each
extra, unneeded database field might slow down a script?

Jul 17 '05
16 2497
Alvaro G Vicario (al************ ******@telecomp uteronline.com) wrote:
: *** Andy Hassall wrote/escribió (Fri, 15 Apr 2005 20:01:06 +0100):
: >>The query itself is faster with *.
: >
: > Any evidence of that? That doesn't make a lot of sense to me.

: It's pretty obvious. Database server doesn't need to look for requested
: fields (I don't know how that works internally, but I'd say it needs to
: compare the strings of requested fields with every table field name), it
: just needs to fetch all columns.

I wouldn't make that assumption, though it may be true.

It is just as possible that the * is converted into a set of columns names
and then retrieved identically to the query that simply listed the column
names.

Personally I think the key factor is programmer productivity and code
correctness.

I find select * very useful because I don't have to decide until later
which columns I am going to use (in reports etc).

If fields are accessed by name then the code will not change if the
database changes.

More commonly, if the database changes then things like reports are
_supposed_ to change - but guess what - the report can incorporate those
changes by simply adding the fields, by name, into the output - none of
the underlying queries have to change. Which means less work and fewer
places for error.

I doubt that select * will introduce the type of fundamental inefficiency
that needs to be avoided at all cost, except in a few obvious cases.

$0.04 (inflation)

--

This space not for rent.
Jul 17 '05 #11
On Mon, 18 Apr 2005 10:01:12 +0200, Alvaro G Vicario
<al************ ******@telecomp uteronline.com> wrote:
*** Andy Hassall wrote/escribió (Fri, 15 Apr 2005 20:01:06 +0100):
The query itself is faster with *.
Any evidence of that? That doesn't make a lot of sense to me.


It's pretty obvious. Database server doesn't need to look for requested
fields (I don't know how that works internally, but I'd say it needs to
compare the strings of requested fields with every table field name), it
just needs to fetch all columns.


How does it know what "all columns" are? It's got to look them up. So you're
effectively back where you started.
Of course, when I say "faster" I just mean 1/1000 seconds.


All this affects is parsing time, which (should) be an insignificant
proportion of total query time. If it makes milliseconds worth of difference to
parsing time I would be surprised.

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #12
On Mon, 18 Apr 2005 10:02:58 -0800, Malcolm Dew-Jones wrote:

More commonly, if the database changes then things like reports are
_supposed_ to change - but guess what - the report can incorporate those
changes by simply adding the fields, by name, into the output - none of
the underlying queries have to change. Which means less work and fewer
places for error.

I doubt that select * will introduce the type of fundamental inefficiency
that needs to be avoided at all cost, except in a few obvious cases.


You've obviously not worked with some of the data sets and queries I've
worked with.

When a SQL report takes 20 minutes to run you know that it's down to bad
design and inefficient programming.

When I started working in IT storing more than three months worth of data
online was virtually unheard of. Now we expect everything to be kept
inpurpetual.

You might not regret your poor design decisions today, but seven years
down the line, you can almost be sure that it'll come back with an
avengance.
Jul 17 '05 #13
CJ Llewellyn (cj**********@g mail.com) wrote:
: On Mon, 18 Apr 2005 10:02:58 -0800, Malcolm Dew-Jones wrote:

: >
: > More commonly, if the database changes then things like reports are
: > _supposed_ to change - but guess what - the report can incorporate those
: > changes by simply adding the fields, by name, into the output - none of
: > the underlying queries have to change. Which means less work and fewer
: > places for error.
: >
: > I doubt that select * will introduce the type of fundamental inefficiency
: > that needs to be avoided at all cost, except in a few obvious cases.

: You've obviously not worked with some of the data sets and queries I've
: worked with.

: When a SQL report takes 20 minutes to run you know that it's down to bad
: design and inefficient programming.

And if the select * is the cause of the slowdown then updating the query
to use exactly the columns required is about as trivial a bit of
maintenance as any I can imagine.

: When I started working in IT storing more than three months worth of data
: online was virtually unheard of. Now we expect everything to be kept
: inpurpetual.

And how does select * have anything to do with that?

: You might not regret your poor design decisions today, but seven years
: down the line, you can almost be sure that it'll come back with an
: avengance.

It's hard to imagine they could be a problem for seven years with no one
checking what was wrong, and just as hard to imagine that they could work
fine for seven years and suddenly become a problem.

I've seen a number of reports containing undetected logic flaws that are
used for some years before the error is detected. Compare that to an
inefficient query - it's pretty easy to detect, possibly easy to fix, and
is nothing more than an annoyance. I think that simple code that avoids
logic errors is much more important.
--

This space not for rent.
Jul 17 '05 #14
*** Andy Hassall wrote/escribió (Mon, 18 Apr 2005 19:04:40 +0100):
All this affects is parsing time, which (should) be an insignificant
proportion of total query time. If it makes milliseconds worth of difference to
parsing time I would be surprised.


Yeah, I thought that was clear in my message.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #15
I'm not sure I get you on this. If you're point is that one shouldn't
get fields one doesn't need, and therefore there is no need to compare
different fields, then we agree, but the agreement is sort of besides
the point. I was trying to explain to people who don't know much about
databases how each unneeded field slowed down a query, and I was
looking for some hard numbers to make my point. If a MediumText field
slows down a query more than a Char(1) field does, then that too would
help make my point.
While you're at it, why not compare the performance
between an Oil Tanker and a Canoe?


That is just what I'm trying to do, in a sense. An oil tanker can hold
more and go across a big ocean, a canoe, on the other hand, could make
its way down small creeks that an oil tanker would never be able to
traverse. Each of these things have different strengths and weaknesses,
and there is a different cost associated with each. In regards the
MediumText and Char fields, I was hoping to quantify the time cost
associated with each.

Jul 17 '05 #16
> And if the select * is the cause of the slowdown then updating the
query
to use exactly the columns required is about as trivial a bit of
maintenance as any I can imagine.


It wouldn't be trivial for a large corporate web design team where some
programmers were responsible for the database teir and others for the
template teir, though it wouldn't be any more complex than using
specific field lists from the start.

Jul 17 '05 #17

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

Similar topics

23
5690
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've reduced my form request to a simple text string entry, instead of my desired optional parameters. As i have been stuck with a single unfathomable glitch for over a year. Basically, if i enter queries such as ; "select * from table" "select * from...
2
2120
by: caprice | last post by:
I'm a MySQL newbie. As I have to access MySQL database in Pocket PC, I'm developing a evc++ program to read and retrieve data from MySQL table. Where can I get some detail information about how "select" and "where" statements work in the format, index and data files of MySQL database? Thanks a tone!!!
17
1486
by: Matko | last post by:
Hello, I need to store data in some database for my application. I need database for easy deployment (small size), that is reliable and maybe fast. What database is best to use in this case? Thanks in advance, John
3
2177
by: NEWSGROUPS | last post by:
Is there any way to find out what database object or table was corrupt after a repair has run in Access 2000? If I can find this out I may find out why the corruption is happening. Any help would be appreciated. Thanks, Mark
0
9706
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10323
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
3
2993
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.