Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we care about data types?

Specifically, in relational database management systems, why do we need to know the data type of a column (more likely, the attribute of an object) at creation time?

To me, data types feel like an optimization, because one data point can be implemented in any number of ways. Wouldn't it be better to assign semantic roles and constraints to a data point and then have the engine internally examine and optimize which data type best serves the user?

I suspect this is where the heavy lifting is and why it's easier to just ask the user rather than to do the work.

What do you think? Where are we headed? Is this a realistic expectation? Or do I have a misguided assumption?

like image 380
Mark Canlas Avatar asked May 29 '09 18:05

Mark Canlas


2 Answers

The type expresses a desired constraint on the values of the column.

like image 80
Peter Stuer Avatar answered Oct 04 '22 18:10

Peter Stuer


The answer is storage space and fixed size rows.

Fixed-size rows are much, MUCH faster to search than variable length rows, because you can seek directly to the correct byte if you know which record number and field you want.

Edit: Having said that, if you use proper indexing in your database tables, the fixed-size rows thing isn't as important as it used to be.

like image 32
Powerlord Avatar answered Oct 04 '22 16:10

Powerlord