Subject Re: How to plan a query
Author danyschaer
Dmitry;

Thank you; here is what I get from PostgreSQL. If you want I can send
you a graphic output that shows MOVI_PRFE as the first step in the
plan.

Dany

" {BITMAPHEAPSCAN "
" :startup_cost 2745.55 "
" :total_cost 700415.71 "
" :plan_rows 739 "
" :plan_width 55 "
" :targetlist ("
" {TARGETENTRY "
" :expr "
" {VAR "
" :varno 1 "
" :varattno 2 "
" :vartype 1042 "
" :vartypmod 14 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 2"
" }"
" :resno 1 "
" :resname PROC "
" :ressortgroupref 0 "
" :resorigtbl 705596 "
" :resorigcol 2 "
" :resjunk false"
" }"
" {TARGETENTRY "
" :expr "
" {VAR "
" :varno 1 "
" :varattno 7 "
" :vartype 1042 "
" :vartypmod 12 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 7"
" }"
" :resno 2 "
" :resname FECH "
" :ressortgroupref 0 "
" :resorigtbl 705596 "
" :resorigcol 7 "
" :resjunk false"
" }"
" {TARGETENTRY "
" :expr "
" {VAR "
" :varno 1 "
" :varattno 8 "
" :vartype 1042 "
" :vartypmod 8 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 8"
" }"
" :resno 3 "
" :resname HORA "
" :ressortgroupref 0 "
" :resorigtbl 705596 "
" :resorigcol 8 "
" :resjunk false"
" }"
" {TARGETENTRY "
" :expr "
" {VAR "
" :varno 1 "
" :varattno 9 "
" :vartype 1043 "
" :vartypmod 204 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 9"
" }"
" :resno 4 "
" :resname DSCR "
" :ressortgroupref 0 "
" :resorigtbl 705596 "
" :resorigcol 9 "
" :resjunk false"
" }"
" )"
" :qual ("
" {OPEXPR "
" :opno 1054 "
" :opfuncid 1048 "
" :opresulttype 16 "
" :opretset false "
" :args ("
" {VAR "
" :varno 1 "
" :varattno 4 "
" :vartype 1042 "
" :vartypmod 5 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 4"
" }"
" {CONST "
" :consttype 1042 "
" :consttypmod -1 "
" :constlen -1 "
" :constbyval false "
" :constisnull false "
" :constvalue 5 [ 20 0 0 0 49 ]"
" }"
" )"
" }"
" {OPEXPR "
" :opno 1054 "
" :opfuncid 1048 "
" :opresulttype 16 "
" :opretset false "
" :args ("
" {VAR "
" :varno 1 "
" :varattno 7 "
" :vartype 1042 "
" :vartypmod 12 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 7"
" }"
" {SUBPLAN "
" :subLinkType 4 "
" :testexpr <> "
" :paramIds (i 2)"
" :plan_id 2 "
" :firstColType 1042 "
" :useHashTable false "
" :unknownEqFalse false "
" :setParam <> "
" :parParam (i 0)"
" :args ("
" {VAR "
" :varno 1 "
" :varattno 2 "
" :vartype 1042 "
" :vartypmod 14 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 2"
" }"
" )"
" }"
" )"
" }"
" )"
" :lefttree "
" {BITMAPINDEXSCAN "
" :startup_cost 0.00 "
" :total_cost 2745.37 "
" :plan_rows 147880 "
" :plan_width 0 "
" :targetlist <> "
" :qual <> "
" :lefttree <> "
" :righttree <> "
" :initPlan <> "
" :extParam (b)"
" :allParam (b)"
" :scanrelid 1 "
" :indexid 722677 "
" :indexqual ("
" {OPEXPR "
" :opno 1054 "
" :opfuncid 1048 "
" :opresulttype 16 "
" :opretset false "
" :args ("
" {VAR "
" :varno 1 "
" :varattno 1 "
" :vartype 1042 "
" :vartypmod 5 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 6"
" }"
" {CONST "
" :consttype 1042 "
" :consttypmod -1 "
" :constlen -1 "
" :constbyval false "
" :constisnull false "
" :constvalue 5 [ 20 0 0 0 80 ]"
" }"
" )"
" }"
" )"
" :indexqualorig ("
" {OPEXPR "
" :opno 1054 "
" :opfuncid 1048 "
" :opresulttype 16 "
" :opretset false "
" :args ("
" {VAR "
" :varno 1 "
" :varattno 6 "
" :vartype 1042 "
" :vartypmod 5 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 6"
" }"
" {CONST "
" :consttype 1042 "
" :consttypmod -1 "
" :constlen -1 "
" :constbyval false "
" :constisnull false "
" :constvalue 5 [ 20 0 0 0 80 ]"
" }"
" )"
" }"
" )"
" :indexstrategy (i 3)"
" :indexsubtype (o 1042)"
" }"
" :righttree <> "
" :initPlan <> "
" :extParam (b)"
" :allParam (b)"
" :scanrelid 1 "
" :bitmapqualorig ("
" {OPEXPR "
" :opno 1054 "
" :opfuncid 1048 "
" :opresulttype 16 "
" :opretset false "
" :args ("
" {VAR "
" :varno 1 "
" :varattno 6 "
" :vartype 1042 "
" :vartypmod 5 "
" :varlevelsup 0 "
" :varnoold 1 "
" :varoattno 6"
" }"
" {CONST "
" :consttype 1042 "
" :consttypmod -1 "
" :constlen -1 "
" :constbyval false "
" :constisnull false "
" :constvalue 5 [ 20 0 0 0 80 ]"
" }"
" )"
" }"
" )"
" }"
""
"Bitmap Heap Scan on "MOVI" m1 (cost=2745.55..700415.71 rows=739
width=55)"
" Recheck Cond: ("HECH" = 'P'::bpchar)"
" Filter: (("TIPO" = '1'::bpchar) AND ("FECH" = (subplan)))"
" -> Bitmap Index Scan on "MOVI_HECH" (cost=0.00..2745.37
rows=147880 width=0)"
" Index Cond: ("HECH" = 'P'::bpchar)"
" SubPlan"
" -> Result (cost=4.57..4.58 rows=1 width=0)"
" InitPlan"
" -> Limit (cost=0.00..4.57 rows=1 width=9)"
" -> Index Scan Backward using "MOVI_PRFE"
on "MOVI" m2 (cost=0.00..68.54 rows=15 width=9)"
" Index Cond: ("PROC" = $0)"
" Filter: (("FECH" IS NOT NULL) AND ("TIPO"
= '1'::bpchar) AND ("HECH" = 'P'::bpchar))"