Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

faster query for - Select * where ID or ID or ID

2 views
Skip to first unread message

Gerhard Haslberger

unread,
Nov 10, 2009, 5:36:17 AM11/10/09
to

I want do do the following:

select price,itemid, FROM `articles` where itemid='56606' OR
itemid='51014' OR itemid='11080' OR itemid='25919' OR itemid='48357' OR
itemid='80651' OR itemid='62374' OR itemid='7652' OR itemid='29208' OR
itemid='80473'
... another 100 ArticleIDs...


What is the fastest way for the DB to parse this query:

This way
WHERE itemid IN ( 56606, 51014, 11080, 25919 )

or is there a better/faster way to save resources?

Thanks!

Johannes Keßler

unread,
Nov 10, 2009, 5:40:02 AM11/10/09
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I'm no export but what does a "EXPLAIN SELECT ...." show for each statement ?

Just place the EXPLAIN keyword in front of your SQL and run it.

regards,

Johannes Keßler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.13 (GNU/Linux)

iEYEARECAAYFAkr5QwIACgkQE++2Zdc7EtesMQCgj49vfgNPZnUfNv4gwdqpJ5pM
3DIAoKfHYCDxyUWEEqs1gBeTKT04rwZT
=4RgX
-----END PGP SIGNATURE-----

Erick T. Barkhuis

unread,
Nov 10, 2009, 5:44:18 AM11/10/09
to
Gerhard Haslberger:

>
> [...] ... another 100 ArticleIDs...


>
>What is the fastest way for the DB to parse this query:
>
>This way
> WHERE itemid IN ( 56606, 51014, 11080, 25919 )
>
>or is there a better/faster way to save resources?

Darn! That's what I would call "need for speed".
You already have it all spelled out for MySQL with
"WHERE itemid IN ( 56606, 51014, 11080, 25919 )", which will be parsed
in less than a millisecond, and you wonder if it can be parsed any
faster?

I would only want to wonder if the query finds and returns the results
efficiently. The parser would probably be the smallest (if at all)
problem.


--
Erick

Gerhard Haslberger

unread,
Nov 10, 2009, 5:59:11 AM11/10/09
to
> and you wonder if it can be parsed any
> faster?

No ;)

But sometimes there are Gurus that write magic words like use MAGIC
instead of Select ...
and got the results in "negativ" - Time...

So: As an sql-beginner, iam happy with your answer

Thanks!

Axel Schwenke

unread,
Nov 10, 2009, 7:54:32 AM11/10/09
to
Gerhard Haslberger <gha...@gmx.de> wrote:
>
> I want do do the following:
>
> select price,itemid, FROM `articles` where itemid='56606' OR
> itemid='51014' OR itemid='11080' OR itemid='25919' OR itemid='48357' OR
> itemid='80651' OR itemid='62374' OR itemid='7652' OR itemid='29208' OR
> itemid='80473'
> ... another 100 ArticleIDs...
>
> What is the fastest way for the DB to parse this query:
>
> This way
> WHERE itemid IN ( 56606, 51014, 11080, 25919 )

Normally the parsing of the SQL code is negligible part of the
query execution time. I'd expect the second variant with IN to
parse a little faster. The execution plan for both variants
should be the same anyway. At least with a 5.x version.

You can profile this!

http://dev.mysql.com/doc/refman/5.1/en/show-profiles.html


XL

0 new messages