~/talk

Solving the knapsack problem with recursive queries and PostgreSQL

Talkat Berlin Buzzwords 2022 · 2022-06-12..06-14· [databases]
slides:none on file

Shows how to solve knapsack inside PostgreSQL using WITH RECURSIVE CTE that builds arrays of picked items, tracks total weight and value, and enforces constraints (bag limit 20). Example items yield an optimal set socks+hat+shoes weight 18 value 33; naive recursion first returns 25 then 33 combinations and deduping by forcing next item_id > last reduces permutations to 15. PostgreSQL 14 adds SEARCH and CYCLE to control breadth/depth traversal and detect repeats but beware cross join explosion and prune the search space.

AI-written summary · about

  1. 0:00Introduction and travel problem
  2. 9:28Why solve it in PostgreSQL
  3. 13:17Recursive queries basics
  4. 18:42Adding constraints to solution
  5. 22:17Optimizing with item ordering
  6. 25:51PostgreSQL 14 search feature
  7. 29:41PostgreSQL 14 cycle feature
  8. 33:56Summary and references
  9. 37:08Q&A on search space pruning
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.