I am trying to determine the best approach to model data that is organized in and needs to be queried in groups and subgroups. Specifically, whether flattening/abstracting into one table and putting the work into the serving computation to filter and group query results (but only one query) will perform better than having separate queries that all need to be run at the same time but of course don't need to be grouped. for example imagine having to serve student test results by category to a dashboard.
approach 1. table for each test
CREATE TABLE mathSkillsTest(
id char,
datetake date,
multiplication_score integer,
division_score integer,
algebra_score integer
student_id integer REFERENCES students (student_id)
)
...create TABLE verbalSkillsTest// all scores still just integers
...create TABLE readingTest//
advantages: Less abstraction easier to reason about, simpler queries, eg var mathscores = (SELECT * FROM mathSkillsTests WHERE student_id = 123)
disadvantage: If the plan is to always query all of the groups, that means we have query each table.
approach 2. One table
CREATE Table abstractTests (
id char,
datetake date,
category varchar, //"math",
testname varchar, // "multiplication"
score integer
student_id integer REFERENCES students (student_id)
)
advantage: one table - one query.
disadvantage: lots of processing and grouping in the query to serve results grouped by category/test/date. also will have disparate data all on one table.
Is one approach more performant & scalable? are either of the approaches violating any best practices?
SELECT
statements trying to ask of the database? Are all skills in a category tested for each test? Or is each test focused on one skill?