Parametric Query Optimization for Linear and Piecewise Linear Cost - - PowerPoint PPT Presentation

parametric query optimization for linear and piecewise
SMART_READER_LITE
LIVE PREVIEW

Parametric Query Optimization for Linear and Piecewise Linear Cost - - PowerPoint PPT Presentation

Parametric Query Optimization for Linear and Piecewise Linear Cost Functions Arvind Hulgeri S. Sudarshan Dept of Computer Science and Engg. Indian Institute of Technology Bombay Parametric query: An example Select * From A, B Where A.x =


slide-1
SLIDE 1

Parametric Query Optimization for Linear and Piecewise Linear Cost Functions

Arvind Hulgeri

  • S. Sudarshan

Dept of Computer Science and Engg. Indian Institute of Technology Bombay

slide-2
SLIDE 2

VLDB 2002 2

Parametric query: An example

Select * From A, B Where A.x = B.y and A.z < ? And B.w < ?

E.g. Cost function f = a1.s1 + a2.s2 + a3

Where, s1 = selectivity of predicate “A.z < ?”

s2 = selectivity of predicate “B.w < ?” a1, a2, a3 are constants

(using merge-join assuming relations are sorted on

join attribute)

slide-3
SLIDE 3

VLDB 2002 3

Conventional Opt v/s PQO

Conventional optimization

Assumes complete knowledge of all cost parameters

E.g. selectivity and resource availability

Generates a single optimal plan for a given query

Parametric query optimization (PQO)

Generates multiple candidate plans, each optimal for

some region of the parameter space

POSP: Parametrically optimal set of plans

Picks appropriate plan at run time

slide-4
SLIDE 4

VLDB 2002 4

PQO: A 1-parameter example

Parameter Cost a c R(b) R(a) R(c) R(d) d b

R(p) = region of optimality of plan p

e

slide-5
SLIDE 5

VLDB 2002 5

Overview

We classify cost functions as:

linear, piecewise linear and non-linear

PQO for linear cost functions

Recursive decomposition algorithm Cost polytope algorithm

PQO for piecewise linear cost functions

Extend a conventional query optimizer

Non-linear cost functions approximated

by piecewise linear cost functions

slide-6
SLIDE 6

VLDB 2002 6

PQO for Linear Cost Functions

Our solutions use a conventional

  • ptimizer as a subroutine

The solutions work for arbitrary number

  • f parameters

Assumption: The conventional optimizer

returns the cost function of the optimal plan

slide-7
SLIDE 7

VLDB 2002 7

Polytope Examples

Lower convex polytope Convex polytope

Convex polytope = intersection of halfspaces

slide-8
SLIDE 8

VLDB 2002 8

Properties of Linear Cost Functions [Ganguly, VLDB98]

If all the vertices of a polytope in the

parameter space have same optimal plan then the plan is optimal at all points within that polytope

Each plan in POSP has only one region of

  • ptimality and the region is a convex

polytope.

slide-9
SLIDE 9

VLDB 2002 9

Recursive Decomposition Algorithm

Start with the parameter space of interest

– a convex polytope

Optimize the vertices of the polytope

using a conventional query optimizer

If two of the vertices of a polytope have

two different optimal plans then

Partition the polytope into two polytopes Continue recursively

slide-10
SLIDE 10

VLDB 2002 10

Shortcomings of the recursive decomposition algorithm

May overpartition the parameter space

and may need to merge partitions in a postpass.

We can reduce number of calls to the

conventional optimizer using cost polytope algorithm

slide-11
SLIDE 11

VLDB 2002 11

Cost Polytope Algorithm

Based on an online polytope construction

algorithm

The cost function of each plan is

represented by a hyperplane in Rn+ 1

N parameter dimensions + 1 cost dimension

Construct the cost polytope

A lower convex polytope that represents the

  • ptimal cost at each point in the parameter

space

slide-12
SLIDE 12

VLDB 2002 12

Cost Polytope: An Example

Parameter Cost c R(b) R(a) R(c)

R(p) = region of optimality of plan p

b a

slide-13
SLIDE 13

VLDB 2002 13

Cost Polytope Algorithm

Start with a initial cost polytope Put vertices of the parameter space polytope

into a queue of vertices to be optimized

Repeat till the queue is empty

Remove and optimize the first vertex in the queue Intersect the cost hyperplane with the cost polytope Project new vertices of the cost polytope onto

parameter space and insert the projection points into the queue

slide-14
SLIDE 14

VLDB 2002 14

Cost polytope algorithm: An example

Parameter Cost

Not optimized Currently optimized Already optimized

a

slide-15
SLIDE 15

VLDB 2002 15

Cost polytope algorithm: An example

Cost Parameter

Not optimized Currently optimized Already optimized

a c

slide-16
SLIDE 16

VLDB 2002 16

Cost polytope algorithm: An example

Cost Parameter

Not optimized Currently optimized Already optimized

a b c

slide-17
SLIDE 17

VLDB 2002 17

Cost polytope algorithm: An example

Cost Parameter

Not optimized Currently optimized Already optimized

a b c

slide-18
SLIDE 18

VLDB 2002 18

Cost polytope algorithm: An example

Cost Parameter

Not optimized Currently optimized Already optimized

a b c

slide-19
SLIDE 19

VLDB 2002 19

Cost polytope algorithm: An example

Cost Parameter

Not optimized Currently optimized Already optimized

a b c

slide-20
SLIDE 20

VLDB 2002 20

Faces and facets of a polytope

3-D polytope facets = 2-faces 1-face 0-face faces = 2-faces U 1-faces U 0-faces N-D polytope facets = (N-1)-faces

U

i = 0 faces = N-1 i-faces F = |faces| f = |facets| = |POSP| v = |0-faces|

slide-21
SLIDE 21

VLDB 2002 21

Complexity of Cost Polytope Algorithm

Cost polytope algorithm makes a

maximum of F calls to the optimizer

The lower bound on the number of calls

is v

Under certain assumptions, the expected

number of calls is (f + v)

In general, in high-dimension, f < < v

slide-22
SLIDE 22

VLDB 2002 22

Piecewise Linear Cost Functions

PQO solutions for linear case do not

extend to piecewise linear case

Parameter Cost

slide-23
SLIDE 23

VLDB 2002 23

Piecewise Linear Cost Function

Partition the parameter space into convex polytopes

Within each partition the cost function is linear in the

parameters

But pre-partitioning the space to make all cost

functions linear in each partition is impractical

Parameter Cost

slide-24
SLIDE 24

VLDB 2002 24

PQO Algorithm for Piecewise Linear Cost Functions (PLCF)

Extend a conventional query optimizer

(System-R or Volcano)

Extensions are intrusive to the query optimizer Partition space only when necessary (“on demand”) Extend plan cost:

Cost Cost function

Extend comparison of alternative operators or plans

Pick min cost plan MinMergeCostFunctions

Extensions work for arbitrary number of

parameters

slide-25
SLIDE 25

VLDB 2002 25

MinMergeCostFunction: An example

Parameter Cost

slide-26
SLIDE 26

VLDB 2002 26

MinMergeCostFunction: An example

Parameter Cost

slide-27
SLIDE 27

VLDB 2002 27

Extending System-R Algorithm

Extended System-R algorithm is exactly

same as basic System-R algorithm except:

Replace cost by cost function Use AddCostFunction instead of simple cost

addition

Use MinMergeCostFunction instead of simple

cost comparision

slide-28
SLIDE 28

VLDB 2002 28

Related Work

Graefe and Karen [SIGMOD'89], Cole and

Graefe [SIGMOD'94], Ioannidis, Ng, Shim and Sellis [VLDB'92]

Ganguly and Krishnamurthy [COMAD'94] Sumit Ganguly [VLDB'98] Sumit Ganguly, A Framework for

Parametric Query Optimization, Unpublished manuscript; Personal Communication, 2001

slide-29
SLIDE 29

VLDB 2002 29

Conclusion

PQO for linear cost functions:

Simple and minimally intrusive Works for arbitrary number of parameters

PQO for piecewise linear cost functions

Intrusive Works for arbitrary number of parameters Very general since nonlinear and discontinuous

cost functions can be approximated to piecewise linear form