Relix

Problem solving

Grain first

Most wrong queries are wrong about the grain before they are wrong about anything else. So before you choose an operator, finish one sentence — "one row per ___" — and write the answer's heading down. That sentence is the grain, and it is the single most useful thing to decide first, because everything else follows from it and almost nothing corrects it.

The grain decides the first operator

The grain is not a detail you settle at the end; it is the shape of the answer, and the shape of the answer chooses the operator that produces it.

Read those the other way and the method appears: say the grain out loud, and the first operator is the one whose output has that grain. A question you cannot phrase as "one row per ___" is usually two questions, which is the subject of decompose into views.

Sketch the answer before you write it

Once the grain is decided, sketch the answer as a tiny inline table — the columns it has, and three or four rows you can work out by hand. This costs a minute and pays twice. It forces the grain to be concrete: if you cannot say what one row looks like, you have not decided the grain yet. And it becomes the test — the known answer you check the finished query against, which is where checking your answer begins.

How a grain goes wrong

Grain rarely goes wrong loudly. It goes wrong quietly, and the query still returns rows — the wrong ones. Three failures account for most of it:

Check the grain you got

The grain you intended and the grain you got are different claims, and the gap between them is where the bug lives. Two checks close it:

Decide the grain, sketch its answer, and these checks turn a query that runs into a query that is right. The rest of the method — the quantifier, the decomposition, the final checklist — all assume the grain is settled first.