Package Queries in Rela2onal Database Systems Ma9eo - - PowerPoint PPT Presentation

package queries
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Scalable ¡

Package ¡Queries ¡

in ¡Rela2onal ¡Database ¡Systems ¡

Ma9eo ¡Brucato ¡ Juan ¡F. ¡Beltran ¡ Azza ¡Abouzied ¡ Alexandra ¡Meliou ¡

slide-2
SLIDE 2

Package ¡Queries ¡

  • An ¡important ¡class ¡of ¡combinatorial ¡
  • p-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 ¡SKETCHREFINE

algorithm ¡

slide-3
SLIDE 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 ¡
slide-4
SLIDE 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 ¡

Summa+on ¡Constraint ¡

  • >= ¡2 ¡Calorie ¡in ¡total ¡

Objec+ve ¡Criterion ¡

  • Lowest ¡total ¡fat ¡intake ¡

Global: ¡ True ¡of ¡the ¡en2re ¡ set ¡of ¡recipes ¡

slide-5
SLIDE 5

Meal ¡Plan ¡

¡

  • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡
  • Exactly ¡3 ¡recipes ¡(cardinality) ¡
  • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡
  • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡

Using ¡SQL ¡

SELECT ¡* ¡ FROM ¡ ¡ ¡Recipes ¡R ¡ WHERE ¡ ¡R.gluten ¡= ¡0 ¡

slide-6
SLIDE 6

Meal ¡Plan ¡

¡

  • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡
  • Exactly ¡3 ¡recipes ¡(cardinality) ¡
  • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡
  • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡

Using ¡SQL ¡

SELECT ¡* ¡ FROM ¡ ¡ ¡Recipes ¡R ¡ WHERE ¡ ¡R.gluten ¡= ¡0 ¡ LIMIT ¡ ¡3 ¡

slide-7
SLIDE 7

Meal ¡Plan ¡

¡

  • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡
  • Exactly ¡3 ¡recipes ¡(cardinality) ¡
  • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡
  • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡

Using ¡SQL ¡

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 ¡

slide-8
SLIDE 8

Meal ¡Plan ¡

¡

  • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡
  • Exactly ¡3 ¡recipes ¡(cardinality) ¡
  • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡
  • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡

Using ¡SQL ¡

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 ¡

slide-9
SLIDE 9

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: ¡Too ¡Expensive! ¡

10-3 101 105 1 2 3 4 5 6 7

Time (s) Package Cardinality SQL Formulation

slide-10
SLIDE 10

Meal ¡Plan ¡

¡

  • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡
  • Exactly ¡3 ¡recipes ¡(cardinality) ¡
  • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡
  • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡

Using ¡SQL ¡

Self-­‑joins ¡are ¡able ¡to ¡express ¡ cardinality ¡and ¡linear ¡

  • constraints. ¡

But ¡what ¡if ¡there ¡is ¡no ¡ ¡ cardinality ¡constraints?... ¡

slide-11
SLIDE 11

Meal ¡Plan ¡

¡

  • All ¡gluten-­‑free ¡recipes ¡(selec2on) ¡
  • Exactly ¡3 ¡recipes ¡(cardinality) ¡
  • At ¡least ¡2 ¡Cal ¡in ¡total ¡(summa2on) ¡
  • Lowest ¡total ¡fat ¡intake ¡(objec2ve) ¡

Using ¡SQL ¡

How ¡many ¡self-­‑joins?... ¡ ¡ It ¡needs ¡SQL’s ¡full ¡recursive ¡power ¡ to ¡build ¡all ¡candidate ¡subsets! ¡

slide-12
SLIDE 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 ¡
slide-13
SLIDE 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 ¡
slide-14
SLIDE 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)

slide-15
SLIDE 15

DIRECT: ¡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 ¡

slide-16
SLIDE 16

PaQL ¡to ¡ILP: ¡Variables ¡

  • Integer ¡Variables: ¡one ¡for ¡each ¡tuple ¡

kcal ¡ fat ¡ 26 ¡ 2.4 ¡ 120 ¡ 8.1 ¡ 13 ¡ 0.1 ¡ 54 ¡ 2.1 ¡

t1 ¡ t2 ¡ tn ¡ … ¡ x1 ¡ x2 ¡ xn ¡ … ¡ x1 ¡∈ Z, x1 ¡≥ 0

How ¡many ¡2mes ¡is ¡t1 ¡repeated ¡in ¡ the ¡result ¡package? ¡ Recipes ¡

slide-17
SLIDE 17

PaQL ¡to ¡ILP: ¡Global ¡Condi2ons ¡

  • SUCH ¡THAT ¡

– COUNT(*) ¡= ¡3 ¡ Σi xi = 3 – SUM(kcal) ¡>= ¡2 ¡ Σi (ti.kcal⋅xi) ≥ 2

  • Objec2ve ¡Criterion ¡

– MINIMIZE ¡SUM(fat) ¡ minimize Σi (ti.fat⋅xi)

slide-18
SLIDE 18

DIRECT: ¡Query ¡Evalua2on ¡

  • 1. Apply ¡base ¡predicate ¡(selec2ons) ¡
  • 2. Formulate ¡ILP ¡
  • 3. Solve ¡ILP ¡

10-3 101 105 1 2 3 4 5 6 7

Time (s) Package Cardinality SQL Formulation ILP Formulation

slide-19
SLIDE 19

Drawbacks ¡of ¡DIRECT ¡

  • Only ¡applicable ¡if ¡data ¡fits ¡en2rely ¡in ¡main ¡

memory ¡

  • It ¡may ¡fail ¡due ¡to ¡the ¡complexity ¡of ¡the ¡ILP ¡

problem ¡

slide-20
SLIDE 20

SKETCHREFINE: ¡Scalable ¡Evalua2on ¡

  • Par22on ¡Data ¡(offline) ¡

– Into ¡groups ¡of ¡similar ¡tuples ¡ – Elect ¡a ¡“representa2ve” ¡tuple ¡for ¡each ¡group ¡

  • SKETCH ¡

– an ¡ini2al ¡package ¡from ¡the ¡representa2ves ¡

  • REFINE ¡

– the ¡ini2al ¡package ¡using ¡real ¡tuples ¡

Returns ¡approximate, ¡feasible, ¡package ¡

slide-21
SLIDE 21

Par22on ¡and ¡SKETCH ¡

1 2 2

Representa-ve ¡ tuples ¡ Sketch ¡ package ¡

fat ¡ kcal ¡

slide-22
SLIDE 22

REFINE ¡

1 2 2 1

G1 G2 G3 G4

2 1

G1 G2 G3 G4

2

G1 G2 G3 G4

1

G1 G2 G3 G4

Guaranteed ¡ feasible ¡ and ¡ approximate ¡

slide-23
SLIDE 23

Approxima2on ¡Guarantees ¡

  • SKETCHREFINE is ¡a ¡(1 ¡± ¡ɛ)6-­‑approxima2on ¡with ¡

respect ¡to ¡DIRECT ¡

  • ɛ ¡limits ¡the ¡par22ons ¡radius ¡
  • The ¡par22on ¡size ¡(number ¡of ¡tuples ¡per ¡

par22on) ¡does ¡not ¡affect ¡the ¡approxima2on ¡ guarantee ¡

slide-24
SLIDE 24

Scalability ¡

SKETCHREFINE ¡ DIRECT ¡

slide-25
SLIDE 25

Par22on ¡Size: ¡Performance ¡Impact ¡

SKETCHREFINE ¡ DIRECT ¡

slide-26
SLIDE 26

Thank ¡You! ¡

Ma9eo ¡Brucato ¡ ma9eo@cs.umass.edu ¡