Sayian wrote:So how are you supposed to optimize data types then?
If i had 30 tables in a database, with user_id as a small_int(4)
Id have to change ALL those data types when i got my 10000th user or my site would break?
That doesnt seem like its a very efficent way to handle information types?
Assuming you were using a database with constraints, you could have a constraint like so:
test2=> create table z(i int check (i<10000));
CREATE TABLE
test2=> insert into z values (10001);
ERROR: new row for relation "z" violates check constraint "z_i"
test2=> alter table z drop constraint z_i;
ALTER TABLE
test2=> insert into z values (10001);
INSERT 2106748451 1
You should make your base types big enough for growth. Resticting them to some arbitrary smaller size like tinyint (or smallint ed...) saves you VERY little in performance terms, but costs you hugely in maintenance at a later date. Just go with int or bigint for most of your int types.
Remember the first rule of performance tuning: Don't