Relix

Problem solving

The best combination within limits

Grain: one row per chosen item · Class: Optimization · Signals: the best, the most/least within, under a budget, maximise, minimise, subject to, without exceeding · Operators: OPTIMIZE

The problem

"We have 50 person-days this quarter and a backlog of features, each with a business value and a build cost. Which subset delivers the most value without going over budget?"

How to recognise it

The question asks for the best combination subject to limits — maximise value under a budget, the cheapest set that covers everything, pick the most within a cap. The tell is that no single row is the answer and no sort finds it: the value of a choice depends on the other choices, because they compete for the same limited resource. That is optimisation, and OPTIMIZE states it directly — an objective to maximise or minimise, and one or more SUBJECT TO constraints.

This is a knapsack, and it is exactly the shape SQL cannot express: the most valuable subset whose costs sum to at most 50 is not a filter, a rank, or an aggregate.

The data

Backlog := [
| feature      | value | cost |
|--------------|-------|------|
| SearchRevamp | 60    | 10   |
| MobileSync   | 100   | 20   |
| Dashboards   | 120   | 30   |
| DarkMode     | 40    | 5    |
];

Recipe: maximise a total under a budget (OPTIMIZE)

State the objective and the constraint; OPTIMIZE returns the chosen input rows, schema unchanged — it is a filter that picks the optimal subset.

Query
query { OPTIMIZE MAXIMIZE SUM(value) SUBJECT TO SUM(cost) <= 50 (Backlog) };
Result
 feature       value  cost
 ────────────  ─────  ────
 SearchRevamp     60    10
 Dashboards      120    30
 DarkMode         40     5
(3 rows)

SUM(value) is what to maximise; SUM(cost) <= 50 is the limit. The solver evaluates every feasible subset — you describe what optimal means, not how to search.

A separate problem per group is PER. Give each team its own budget in one statement:

Query
TeamBacklog := [
| team    | feature      | value | cost |
|---------|--------------|-------|------|
| search  | SearchRevamp | 60    | 10   |
| search  | Dashboards   | 120   | 30   |
| mobile  | MobileSync   | 100   | 20   |
| mobile  | DarkMode     | 40    | 5    |
];

query { OPTIMIZE MAXIMIZE SUM(value) SUBJECT TO SUM(cost) <= 30 PER team (TeamBacklog) };
Result
 team    feature     value  cost
 ──────  ──────────  ─────  ────
 search  Dashboards    120    30
 mobile  MobileSync    100    20
 mobile  DarkMode       40     5
(3 rows)

Variations

Pitfalls

Check it