mysql - One column references on multiple different tables -


think of platform-wide commenting-system. comment can added users profile, website section, comment or x other things.

that means comment has "addressee_id" , addressee_id can reference on different tables.

  • comments (id, adresseee_id, ..., ...)
  • sections (id, ...)
  • users (id, ...)

what best way define on table join?

three possible ways:

  1. denormalization remove other tables , add x columns "comments"-table problem: lot of empty fields.

  2. another table "pages" page_ids. each table gets column "page_id" fk on pages.id. here have make x joins each request. sounds expensive.

  3. comments-table gets column "addresse_type" here have implement if/else logics query expensive , not easy maintain.

what suggest?

thanks phil


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -