Should I use a row table to make the database more efficient?

Let's say you have a database with one table, for example ...

---------------------------------------------
| Name    |  FavoriteFood                   |
---------------------------------------------
| Alice   | Pizza                           |
| Mark    | Sushi                           |
| Jack    | Pizza                           |
---------------------------------------------

It would be more spatially effective to have an extra table called "Rows" in which the rows are stored, and change the FavoriteFood column to an index in the row table. In the above example, "Pizza" looks like it is stored twice, but with an extra table, it is stored only once. Of course, suppose there are 1,000,000 rows and 1,000 unique rows instead of three rows and 2 unique rows.

Edit: we do not know what FavoriteFoods is in advance: they are provided by users. A programmatic interface to a row table would be something like ...

String GetString(int ID) { return String at with Row-ID == ID }

int GetID(String s) {
  if s exists, return row-id;
  else {
    Create new row;
    return new row id;
  }
}

, - , , ?

+3
4

, , ( + ).

3NF ( ). , .

+3

? , , FavoriteFood ( , , ), , , , . , , , , , .

+4

, , , Pizzas , , u . , , .

. U , , .

+2

"":

  • , , .
  • , - - I\O

:

  • , . ( ) ( ) . , (Strings.Count()) ~ , .

. . .

+1

Source: https://habr.com/ru/post/1710948/


All Articles