mysql - Should I use a single table for many categorized rows? -
i want implement user event tracking in website statistics etc. thought creating table called tracking_events
contain following fields:
| id (int, primart) | | event_type (int) | | user_id (int) | | date_happened (timestamp)|
this table contain large amount of rows (let's assume @ least every page view tracked event , there 1,000 daily visitors site).
is practice create table event_type
field differentiate between different, yet identically structured rows?
or better idea make separate table each type? e.g.:
table pageview_events
| id (int, primart) | | user_id (int) | | date_happened (timestamp)|
table share_events
| id (int, primart) | | user_id (int) | | date_happened (timestamp)|
and on 5-10 tables.
(the main concern performance when selecting rows where event_type = ...
)
thanks.
it depends. if need have them separated, because querying them separately, splitting them 2 tables should fine. saves having store discriminator column.
but... if need query these sets together, if single table, easier have them stored together, discriminator column.
as far where event_type=
, if there 2 distinct values, pretty distribution, index on column isn't going much. including column leading column in multicolumn index(es) way go, if large number of queries include equality predicate on column.
obviously, if these tables going "large", you'll want them indexed appropriately queries.
Comments
Post a Comment