473,795 Members | 3,428 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 #1
16 2492
lk******@geocit ies.com wrote:

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?


I've not got any figures on performance, although depending on the number of
columns involved and their size it could be quite a bit. I can tell you of
one instance I came across with another DBMS using ODBC, which just loves
to read the system catalog for information about everything right down to
column level, that to return 5000 rows of user data from a 70 column table
took over 2 million page I/Os to the system catalog. Not exactly great
for performance.

In my opinion there are other, more important, reasons for not using "SELECT
*". These principally relate to what will happen to the application if
you change the database structure. For example, in the table you gave lets
assume we decide to add a column publisher varchar(255) immediately after
the author column. Let's also assume that you access the columns in a
resultset by position, rather than by name. Now if you use a "select *"
where you displayed navigationText before you will now display publisher.

Similar problems occur with insert statements where the column list isn't
specified, but just the values list. Everything is OK until you add a
column. If the last column is "NOT NULL" the statement breaks. Worse
though you can end up putting data into the wrong places.

HTH

Phil
Jul 17 '05 #2
lk******@geocit ies.com wrote:
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?


I think you will find it isn't going to make much difference
unless you are retrieving several million rows.

The amount of data read is dictated by the physical read
characteristics of the disk subsystem. The database takes what
the disk subsystem hands off to the OS, locates the desired
table row, and then parses the row to pull out either each
column or the specified columns.

The bulk of the time is spent waiting for disk i/o completion
and the difference in time a high performance database like
MySQL spends parsing the data and extracting and presenting
either every column or a subset of the columns isn't significant.
BTW, I agree with Philip Nelson, who responded earlier, and felt
that SELECT * should be avoided due to possible problems arising
from future maintenance changes to the database.
HTH

Jerry

Jul 17 '05 #3

"Philip Nelson" <te*****@scotdb .com> wrote in message
news:we******** *************** @news.easynews. com...
lk******@geocit ies.com wrote:

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?
I've not got any figures on performance, although depending on the number
of
columns involved and their size it could be quite a bit. I can tell you
of
one instance I came across with another DBMS using ODBC, which just loves
to read the system catalog for information about everything right down to
column level, that to return 5000 rows of user data from a 70 column table
took over 2 million page I/Os to the system catalog. Not exactly great
for performance.

In my opinion there are other, more important, reasons for not using
"SELECT
*". These principally relate to what will happen to the application if
you change the database structure. For example, in the table you gave
lets
assume we decide to add a column publisher varchar(255) immediately after
the author column. Let's also assume that you access the columns in a
resultset by position, rather than by name. Now if you use a "select *"
where you displayed navigationText before you will now display publisher.


That's the primary reason for returning associative lists, so that you can
reference items by name instead of their position. That way is does not
matter in what order the columns are retrieved.
Similar problems occur with insert statements where the column list isn't
specified, but just the values list. Everything is OK until you add a
column. If the last column is "NOT NULL" the statement breaks. Worse
though you can end up putting data into the wrong places.


If you do what I do and construct all INSERT, UPDATE and DELETE statements
programmaticall y then this problem will never appear.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #4
On 9 Apr 2005 12:40:13 -0700, lk******@geocit ies.com wrote:
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?


Well, It Depends.

How wide is the row? If you've got a LONGTEXT in there with 1Mb of data, the
impact is going to be far greater if you fetch it when you don't need it.

What's your query? I don't know if MySQL has this feature, but in Oracle,
let's say you query just primary key columns; this can be answered more quickly
by scanning the index rather than the table (since the index is smaller), which
eliminates lots of lookups from the index to the table itself. But if you
request columns that aren't in the index, then it's got to hit the table to get
the data. So the same query conditions with a different select column list can
be executed very differently.

--
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 #5
Thanks for all the terrific feedback. I agree its best to reference
fields by their names.

But no articles that anyone can me to? No benchmarks from the open
source community? Disappointing.

Does it strike this group as likely that MediumText is likely to cause
a bigger hit than CHAR 1 ????

Jul 17 '05 #6
*** lk******@geocit ies.com wrote/escribió (9 Apr 2005 12:40:13 -0700):
SELECT * FROM weblogs

as opposed to

SELECT id, headline FROM weblogs


The query itself is faster with *. Performance issues arise when you are
reading fields you don't need, which can happen:

* When your script doesn't use all table fields.

* If you add new fields to a table and do not edit *all* the scripts that
use these tables.

Performance gain with * is minimal but potential loss is huge: imagine you
add a BLOB field to store files (let's say, a picture of the country) and
retrieve the complete image from DB everytime you want to create a <select>
field to choose countries.
--
-- Á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 #7
On Fri, 15 Apr 2005 13:44:00 +0200, Alvaro G Vicario
<al************ ******@telecomp uteronline.com> wrote:
SELECT * FROM weblogs

as opposed to

SELECT id, headline FROM weblogs


The query itself is faster with *.


Any evidence of that? That doesn't make a lot of sense to me.

--
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 #8
On Tue, 12 Apr 2005 13:21:51 -0700, lkrubner wrote:
Thanks for all the terrific feedback. I agree its best to reference
fields by their names.

But no articles that anyone can me to? No benchmarks from the open
source community? Disappointing.

Does it strike this group as likely that MediumText is likely to cause
a bigger hit than CHAR 1 ????


Doesn't it strike you as bleading obvious that a CHAR(1) can not possibly
be used for the same purposes as BLOB data type? Therefore comparing the
performance characteristics of both types is an exercise left upto morons
and idiots?

While you're at it, why not compare the performance between an Oil Tanker
and a Canoe?

Jul 17 '05 #9
*** 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.

Of course, when I say "faster" I just mean 1/1000 seconds.

--
-- Á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 #10

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

Similar topics

23
5687
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
2119
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
2175
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
9519
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,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
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
9040
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
7538
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
6780
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.