PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Indexing one byte flags - what implementattion is better
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Indexing one byte flags - what implementattion is better

Réponse
 
LinkBack Outils de la discussion
Vieux 27/12/2007, 21h19   #1
Artem Kuchin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Indexing one byte flags - what implementattion is better

Maybe someone could provide a good resonable
input on this issue.

Let's say i have a table products

CASE 1:

table: products

id int unsigned not null,
name char(128) not null,
f_new tinyint not null

id - is basically the id of a product
name - is the name of a product
f_new - is a one byte flag. If it is 1 the product is condireed new.


In this case to select all new products including name i need to do:

select id, name from products wher f_new=1

CASE 2:

The above can be done another way - via two table,
one products table and another one - listing all ids
for new products

create table products (
id int unsigned not null,
name char(128) not null,
primay key (id)
);

create table newproducts (
product_id int unsigned not null,
primay key (id)
);


If product is is in newproducts table that it is
a new product.

To choose all new products including name i need to do:

SELECT id,name
FROM newproducts
INNER JOIN products ON products.id=newproducts.product_id

The questions are:

1) which way is FASTER?
2) which way eats less memory?
3) which way eats less cpu?
4) which way eats less hdd io?

There are several cases for each question:
1) <1000 products - i think both methods are pretty much the same
in this case because all of the data woul be cached in memory

2) 100000 products, 30000 new products - interesting to know
which method is better here and how each of the method performs.

3) 100000 products, 50 new products - interesting to know
which method is better here and how each of the method performs.


I will greately appriciate input on this issue.

--
Artem

  Réponse avec citation
Vieux 27/12/2007, 21h26   #2
Garris, Nicole
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Indexing one byte flags - what implementattion is better

Is id a sequential number? And is it referenced by other tables? If so,
and if over time new products become "old" products, then CASE 2 is more
complex, because when moving a product (i.e., a row) from the new
product table to the old product table, the value of id needs to stay
the same. So for CASE 2 you'll need a third object to keep track of the
highest value for id.

-----Original Message-----
From: Artem Kuchin [mailto:matrix@itlegion.ru]
Sent: Thursday, December 27, 2007 1:19 PM
To: mysql@lists.mysql.com
Subject: Indexing one byte flags - what implementattion is better

Maybe someone could provide a good resonable
input on this issue.

Let's say i have a table products

CASE 1:

table: products

id int unsigned not null,
name char(128) not null,
f_new tinyint not null

id - is basically the id of a product
name - is the name of a product
f_new - is a one byte flag. If it is 1 the product is condireed new.


In this case to select all new products including name i need to do:

select id, name from products wher f_new=1

CASE 2:

The above can be done another way - via two table,
one products table and another one - listing all ids
for new products

create table products (
id int unsigned not null,
name char(128) not null,
primay key (id)
);

create table newproducts (
product_id int unsigned not null,
primay key (id)
);


If product is is in newproducts table that it is
a new product.

To choose all new products including name i need to do:

SELECT id,name
FROM newproducts
INNER JOIN products ON products.id=newproducts.product_id

The questions are:

1) which way is FASTER?
2) which way eats less memory?
3) which way eats less cpu?
4) which way eats less hdd io?

There are several cases for each question:
1) <1000 products - i think both methods are pretty much the same
in this case because all of the data woul be cached in memory

2) 100000 products, 30000 new products - interesting to know
which method is better here and how each of the method performs.

3) 100000 products, 50 new products - interesting to know
which method is better here and how each of the method performs.


I will greately appriciate input on this issue.

--
Artem


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=n...ris@dof.ca.gov

  Réponse avec citation
Vieux 28/12/2007, 08h40   #3
Artem Kuchin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Indexing one byte flags - what implementattion is better

Garris, Nicole wrote:
> Is id a sequential number? And is it referenced by other tables? If
> so, and if over time new products become "old" products, then CASE 2
> is more complex, because when moving a product (i.e., a row) from the
> new product table to the old product table, the value of id needs to
> stay the same. So for CASE 2 you'll need a third object to keep track
> of the highest value for id.


I think you did not get it right. There is no MOVING of products.
All product are stored in 'products' table only, and newproducts
is just is kind of FLAG table. It contains ONLY ids of products
considered new, nothing else. So, if product is new then its is
of course in products table and in newproducts table and if it is not new
then it is only in 'products' table.

ID is a seqential number (but no auto_increment - i hate it).

PS: top posting is really popular in mysql list!

--
Artem


> -----Original Message-----
> From: Artem Kuchin [mailto:matrix@itlegion.ru]
> Sent: Thursday, December 27, 2007 1:19 PM
> To: mysql@lists.mysql.com
> Subject: Indexing one byte flags - what implementattion is better
>
> Maybe someone could provide a good resonable
> input on this issue.
>
> Let's say i have a table products
>
> CASE 1:
>
> table: products
>
> id int unsigned not null,
> name char(128) not null,
> f_new tinyint not null
>
> id - is basically the id of a product
> name - is the name of a product
> f_new - is a one byte flag. If it is 1 the product is condireed new.
>
>
> In this case to select all new products including name i need to do:
>
> select id, name from products wher f_new=1
>
> CASE 2:
>
> The above can be done another way - via two table,
> one products table and another one - listing all ids
> for new products
>
> create table products (
> id int unsigned not null,
> name char(128) not null,
> primay key (id)
> );
>
> create table newproducts (
> product_id int unsigned not null,
> primay key (id)
> );
>
>
> If product is is in newproducts table that it is
> a new product.
>
> To choose all new products including name i need to do:
>
> SELECT id,name
> FROM newproducts
> INNER JOIN products ON products.id=newproducts.product_id
>
> The questions are:
>
> 1) which way is FASTER?
> 2) which way eats less memory?
> 3) which way eats less cpu?
> 4) which way eats less hdd io?
>
> There are several cases for each question:
> 1) <1000 products - i think both methods are pretty much the same
> in this case because all of the data woul be cached in memory
>
> 2) 100000 products, 30000 new products - interesting to know
> which method is better here and how each of the method performs.
>
> 3) 100000 products, 50 new products - interesting to know
> which method is better here and how each of the method performs.
>
>
> I will greately appriciate input on this issue.
>
> --
> Artem
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=n...ris@dof.ca.gov

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12959 seconds with 11 queries