List:General Discussion« Previous MessageNext Message »
From:Artem Kuchin Date:June 15 2009 9:32am
Subject:Fastest way to select on 0/1 flag
View as plain text  

I cannot figure out the fastest way to do a select on the floowing field:

f_spec    tinyint not null;

It is a table of 100 000 records of products and f_spec is set only for 
about 200 products.

I figure it could be done in two ways:

1) create an index on f_spec and do simple
select * from products where f_spec=1;

2) create a separate table

create table specs (
    product_id   int;
    primary key (product_id)

then select ids from this table and join with the products table if needed.

What is the best way?

Also, it is often needed to know only the fact that there is any product 
with f_spec set.
Is using index and doing
select id from products where f_spec=1 limit 1
will be very fast ?

Fastest way to select on 0/1 flagArtem Kuchin15 Jun
  • Re: Fastest way to select on 0/1 flagDarryle Steplight15 Jun