package queries
play

Package Queries in Rela2onal Database Systems Ma9eo - PowerPoint PPT Presentation

Scalable Package Queries in Rela2onal Database Systems Ma9eo Brucato Juan F. Beltran Azza Abouzied Alexandra Meliou Package Queries An important class


  1. Scalable ¡ Package ¡Queries ¡ in ¡Rela2onal ¡Database ¡Systems ¡ Ma9eo ¡Brucato ¡ Juan ¡F. ¡Beltran ¡ Azza ¡Abouzied ¡ Alexandra ¡Meliou ¡

  2. Package ¡Queries ¡ • An ¡important ¡class ¡of ¡ combinatorial ¡ op-miza-on ¡queries ¡ • Largely ¡ unsupported ¡by ¡exis2ng ¡technology ¡ • We ¡make ¡them ¡ first-­‑class ¡ci+zens ¡ in ¡rela2onal ¡ databases: ¡ – The ¡Package ¡Query ¡Language ¡(PaQL) ¡ – PaQL ¡to ¡Integer ¡Linear ¡Programming ¡(ILP) ¡ • Scalable ¡evalua2on ¡through ¡the ¡ S KETCH R EFINE algorithm ¡

  3. Example: ¡Meal ¡Planning ¡ A ¡die2cian ¡wants ¡to ¡build ¡a ¡ Meal ¡Plan ¡for ¡a ¡pa2ent ¡ Meal ¡Plan ¡ ¡ • 3 ¡gluten-­‑free ¡recipes ¡(breakfast, ¡lunch, ¡dinner) ¡ • At ¡least ¡2 ¡Cal ¡ in ¡total ¡ • Lowest ¡ total ¡fat ¡intake ¡

  4. A ¡Meal ¡Plan ¡is ¡a ¡“ Package ” ¡ Meal ¡Plan ¡ 3 ¡gluten-­‑free ¡recipes ¡(breakfast, ¡lunch, ¡dinner) ¡ • At ¡least ¡2 ¡Cal ¡ • Lowest ¡total ¡fat ¡intake ¡ • Base ¡Constraint ¡(selec+on ¡predicate) ¡ • All ¡recipes ¡in ¡the ¡meal ¡plan ¡are ¡ gluten-­‑free ¡ Cardinality ¡Constraint ¡ • 3 ¡recipes ¡ Global : ¡ Summa+on ¡Constraint ¡ True ¡of ¡the ¡en2re ¡ • >= ¡2 ¡Calorie ¡in ¡ total ¡ set ¡of ¡recipes ¡ Objec+ve ¡Criterion ¡ • Lowest ¡total ¡fat ¡intake ¡

  5. Using ¡SQL ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ SELECT ¡* ¡ FROM ¡ ¡ ¡Recipes ¡R ¡ WHERE ¡ ¡R.gluten ¡= ¡0 ¡

  6. Using ¡SQL ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ SELECT ¡* ¡ FROM ¡ ¡ ¡Recipes ¡R ¡ WHERE ¡ ¡R.gluten ¡= ¡0 ¡ LIMIT ¡ ¡3 ¡

  7. Using ¡SQL ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ SELECT ¡* ¡ FROM ¡ ¡ ¡Recipes ¡R1, ¡Recipes ¡R2, ¡Recipes ¡R3 ¡ WHERE ¡ ¡ ¡ ¡ ¡R1.gluten ¡= ¡0 ¡AND ¡R2.gluten ¡= ¡0 ¡AND ¡R3.gluten ¡= ¡0 ¡ ¡ ¡AND ¡ R1.kcal ¡+ ¡R2.kcal ¡+ ¡R3.kcal ¡>= ¡2.0 ¡

  8. Using ¡SQL ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ SELECT ¡* ¡ FROM ¡ ¡ ¡Recipes ¡R1, ¡Recipes ¡R2, ¡Recipes ¡R3 ¡ WHERE ¡ ¡ ¡ ¡ ¡R1.gluten ¡= ¡0 ¡AND ¡R2.gluten ¡= ¡0 ¡AND ¡R3.gluten ¡= ¡0 ¡ ¡ ¡AND ¡R1.kcal ¡+ ¡R2.kcal ¡+ ¡R3.kcal ¡>= ¡2.0 ¡ ORDER ¡BY ¡ ¡ ¡R1.fat ¡+ ¡R2.fat ¡+ ¡R3.fat ¡

  9. Self-­‑joins: ¡Too ¡Expensive! ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ SQL Formulation 10 5 Time (s) 10 1 10 -3 1 2 3 4 5 6 7 Package Cardinality

  10. Using ¡SQL ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ Self-­‑joins ¡are ¡able ¡to ¡express ¡ cardinality ¡and ¡ linear ¡ constraints. ¡ But ¡what ¡if ¡there ¡is ¡ no ¡ ¡ cardinality ¡constraints ?... ¡

  11. Using ¡SQL ¡ Meal ¡Plan ¡ ¡ • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ How ¡many ¡self-­‑joins?... ¡ ¡ It ¡needs ¡SQL’s ¡full ¡recursive ¡power ¡ to ¡build ¡all ¡candidate ¡subsets! ¡

  12. Recap: ¡Why ¡is ¡SQL ¡insufficient? ¡ 1. With ¡known ¡cardinality, ¡ self-­‑joins ¡can ¡ express ¡package ¡queries, ¡but ¡they ¡are ¡ too ¡ expensive ¡to ¡compute ¡ 2. Without ¡known ¡cardinality, ¡self-­‑joins ¡are ¡ not ¡ powerful ¡enough ¡ 3. The ¡self-­‑join ¡solu2on ¡loses ¡in ¡declara-veness ¡

  13. Packages ¡as ¡first-­‑class ¡ci2zens ¡in ¡ database ¡systems ¡ • Packages ¡are ¡ not ¡unique ¡to ¡each ¡applica2on ¡ • Nor ¡are ¡the ¡ algorithms ¡for ¡construc2ng ¡them ¡ • The ¡ data ¡typically ¡resides ¡in ¡a ¡database ¡ We ¡introduce: ¡ • A ¡declara2ve ¡package ¡query ¡language: ¡ PaQL ¡ • PaQL ¡to ¡ILP ¡ transla-on ¡method ¡ • Scalable ¡PaQL ¡evalua2on ¡method ¡

  14. PaQL: ¡The ¡Package ¡Query ¡Language ¡ Meal ¡Plan ¡ All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡ • Exactly ¡3 ¡recipes ¡(cardinality) ¡ • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡ • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡ • SELECT PACKAGE PACKAGE (R) FROM Recipes R WHERE R.gluten=0 SUCH THAT SUCH THAT COUNT(*)=3 AND SUM(kcal)>=2 MINIMIZE MINIMIZE SUM(fat)

  15. D IRECT : ¡PaQL ¡to ¡ILP ¡Transla2on ¡ • An ¡ILP ¡problem ¡consists ¡of: ¡ – A ¡set ¡of ¡ integer ¡variables ¡ – A ¡set ¡of ¡ linear ¡constraints ¡over ¡the ¡variables ¡ – A ¡ linear ¡objec-ve ¡func-on ¡ over ¡the ¡variables ¡ • An ¡ILP ¡solu2on ¡consists ¡of: ¡ – An ¡ assignment ¡ to ¡each ¡of ¡the ¡integer ¡variables ¡

  16. PaQL ¡to ¡ILP: ¡Variables ¡ • Integer ¡Variables: ¡one ¡for ¡each ¡tuple ¡ Recipes ¡ kcal ¡ fat ¡ How ¡many ¡2mes ¡is ¡ t1 ¡repeated ¡in ¡ the ¡result ¡package? ¡ 26 ¡ 2.4 ¡ x1 ¡ ∈ Z, x1 ¡ ≥ 0 t1 ¡ x1 ¡ 120 ¡ 8.1 ¡ t2 ¡ x2 ¡ 13 ¡ 0.1 ¡ … ¡ … ¡ 54 ¡ 2.1 ¡ tn ¡ xn ¡

  17. PaQL ¡to ¡ILP: ¡Global ¡Condi2ons ¡ • SUCH ¡THAT ¡ – COUNT(*) ¡= ¡3 ¡ Σ i x i = 3 – SUM(kcal) ¡>= ¡2 ¡ Σ i (t i .kcal ⋅ x i ) ≥ 2 • Objec2ve ¡Criterion ¡ – MINIMIZE ¡SUM(fat) ¡ minimize Σ i (t i .fat ⋅ x i )

  18. D IRECT : ¡Query ¡Evalua2on ¡ 1. Apply ¡base ¡predicate ¡(selec2ons) ¡ 2. Formulate ¡ILP ¡ 3. Solve ¡ILP ¡ SQL Formulation ILP Formulation 10 5 Time (s) 10 1 10 -3 1 2 3 4 5 6 7 Package Cardinality

  19. Drawbacks ¡of ¡ D IRECT ¡ • Only ¡applicable ¡if ¡data ¡ fits ¡ en2rely ¡in ¡main ¡ memory ¡ • It ¡ may ¡fail ¡ due ¡to ¡the ¡ complexity ¡of ¡the ¡ILP ¡ problem ¡

  20. S KETCH R EFINE : ¡Scalable ¡Evalua2on ¡ • Par22on ¡Data ¡(offline) ¡ – Into ¡groups ¡of ¡similar ¡tuples ¡ – Elect ¡a ¡“representa2ve” ¡tuple ¡for ¡each ¡group ¡ • S KETCH ¡ – an ¡ini2al ¡package ¡from ¡the ¡representa2ves ¡ • R EFINE ¡ – the ¡ini2al ¡package ¡using ¡real ¡tuples ¡ Returns ¡approximate, ¡feasible, ¡package ¡

  21. Par22on ¡and ¡S KETCH ¡ 0 2 kcal ¡ 2 1 fat ¡ Representa-ve ¡ Sketch ¡ tuples ¡ package ¡

  22. R EFINE ¡ G 1 G 2 G 1 G 2 0 0 2 G 3 G 3 2 2 2 1 1 1 G 4 G 4 G 1 G 2 G 1 G 2 Guaranteed ¡ feasible ¡ G 3 G 3 and ¡ 1 approximate ¡ G 4 G 4

  23. Approxima2on ¡Guarantees ¡ • S KETCH R EFINE is ¡a ¡(1 ¡± ¡ɛ) 6 -­‑approxima2on ¡with ¡ respect ¡to ¡D IRECT ¡ • ɛ ¡limits ¡the ¡par22ons ¡radius ¡ • The ¡par22on ¡size ¡(number ¡of ¡tuples ¡per ¡ par22on) ¡does ¡not ¡affect ¡the ¡approxima2on ¡ guarantee ¡

  24. Scalability ¡ D IRECT ¡ S KETCH R EFINE ¡

  25. Par22on ¡Size: ¡Performance ¡Impact ¡ D IRECT ¡ S KETCH R EFINE ¡

  26. Thank ¡You! ¡ Ma9eo ¡Brucato ¡ ma9eo@cs.umass.edu ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend