czwartek, 14 lutego 2013

A database design problem

This time in English, because I want share this with my international friends.

The problem statement is very easy:
  1. Online store (everybody knows what is it about)
  2. Each user has Address.
  3. You can place Order for one Product.
  4. To simplify you have only 3 tables: Order, Product, Address.
The most straightforward approach would be to model this like this:


But then when Product or Address is updated it would affect Order that was placed. Of course this behaviour would be unacceptable from business perspective. If you would like to keep this design you could make Address and Product rows immunable. So every time user changes address new row is added to Address table and every product modification is a new row Product table. This could work in this scenario but:
  1. There is a risk that database would grow.(not a big deal)
  2. How would you solve that some other tables are related to Product or Address. With every Product, Address change you should write logic to replace foreign keys with new values.
  3. Change of object should be update in database. That's what I feel :).
That is why, I would choose alternative approach. 

It looks like denormalized and as wikipedia states:
A standard piece of database design guidance is that the designer should create a fully normalized design 
but in my opinion it isn't denormalized. When order is placed you have to take a snapshot of related tables Product and Address. Since the relations Order-Product and Order-Address is 1-1 you can just add fields to Order.

What are your opinions? How can you design it better?

poniedziałek, 7 stycznia 2013

Rankingi czytelnictwa - jak mnie to wkurza!!

Co pewien czas w telewizji pojawia się raport o stanie czytelnictwa. I tak dowiadujemy się, że statystyczny Polak czyta mniej niż jedną książkę w miesiącu. Ja rozumiem, że aby mówić o społeczeństwie trzeba używać statystyki. Problemem jest to, że ludzie później wartościują się nawzajem na podstawie liczby przeczytanych książek, która jest nieistotna.

Dla mnie są najważniejsze unikalne wrażenia, przemyślenia, doświadczenia, wnioski itd., które wynikają z lektury. Wierzę, że niejedna książka, którą ja skreślałem mogłaby zmienić czyjeś życie. Tak samo książki dla innych nudne, zmieniają moje.

Dlaczego bezrefleksyjne czytelnictwo nie jest tępione a gloryfikowane? Ostatnio nawet słyszałem, jak znajomy był dumny z tego, że czyta książki, które mają renomę trudnych. Automatycznie klasyfikujemy czytelnika Dostojowskiego jako lepszego od fascynata science fiction. A dlaczego w ogóle zawsze wartościujemy książkę jako lepszą od filmu, film lepszy od serialu itd. Ta szkolna hierarchia jest dla mnie śmieszna i przestarzała. Tym bardziej, że tym, co ostatnio zrobiło na mnie prawdziwe wrażenie był ostatni odcinek Breaking Bad.

SyntaxHighlighter