8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.5 1997/04/09 01:52:04 vadim Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.6 1997/04/24 16:07:14 vadim Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -499,6 +499,8 @@ IndexSelectivity(Oid indexrelid,
499
499
float64data npages , select ;
500
500
float64 amopnpages , amopselect ;
501
501
Oid relam ;
502
+ bool nphack = false;
503
+ float64data fattr_select = 1.0 ;
502
504
503
505
indRel = SearchSysCacheTuple (RELOID ,
504
506
ObjectIdGetDatum (indexrelid ),
@@ -515,6 +517,15 @@ IndexSelectivity(Oid indexrelid,
515
517
elog (WARN , "IndexSelectivity: index %d not found" ,
516
518
indexrelid );
517
519
index = (IndexTupleForm )GETSTRUCT (indexTuple );
520
+
521
+ /*
522
+ * Hack for non-functional btree npages estimation:
523
+ * npages = index_pages * selectivity_of_1st_attr_clause(s)
524
+ * - vadim 04/24/97
525
+ */
526
+ if ( relam == BTREE_AM_OID &&
527
+ varAttributeNumbers [0 ] != InvalidAttrNumber )
528
+ nphack = true;
518
529
519
530
npages = 0.0 ;
520
531
select = 1.0 ;
@@ -556,7 +567,10 @@ IndexSelectivity(Oid indexrelid,
556
567
elog (WARN , "IndexSelectivity: no amop %d %d" ,
557
568
indclass , operatorObjectIds [n ]);
558
569
amop = (Form_pg_amop )GETSTRUCT (amopTuple );
559
- amopnpages = (float64 ) fmgr (amop -> amopnpages ,
570
+
571
+ if ( !nphack )
572
+ {
573
+ amopnpages = (float64 ) fmgr (amop -> amopnpages ,
560
574
(char * ) operatorObjectIds [n ],
561
575
(char * ) indrelid ,
562
576
(char * ) varAttributeNumbers [n ],
@@ -573,8 +587,9 @@ IndexSelectivity(Oid indexrelid,
573
587
if ((i = npages ) < npages ) /* ceil(npages)? */
574
588
npages += 1.0 ;
575
589
#endif
576
- npages += PointerIsValid (amopnpages ) ? * amopnpages : 0.0 ;
577
-
590
+ npages += PointerIsValid (amopnpages ) ? * amopnpages : 0.0 ;
591
+ }
592
+
578
593
amopselect = (float64 ) fmgr (amop -> amopselect ,
579
594
(char * ) operatorObjectIds [n ],
580
595
(char * ) indrelid ,
@@ -583,15 +598,27 @@ IndexSelectivity(Oid indexrelid,
583
598
(char * ) constFlags [n ],
584
599
(char * ) nIndexKeys ,
585
600
(char * ) indexrelid );
601
+
602
+ if ( nphack && varAttributeNumbers [n ] == index -> indkey [0 ] )
603
+ fattr_select *= PointerIsValid (amopselect ) ? * amopselect : 1.0 ;
604
+
586
605
select *= PointerIsValid (amopselect ) ? * amopselect : 1.0 ;
587
606
}
588
607
/*
589
608
* Estimation of npages below is hack of course, but it's
590
609
* better than it was before. - vadim 04/09/97
591
610
*/
592
- if ( nIndexKeys > 1 )
593
- npages = npages / (1.0 + nIndexKeys );
594
- * idxPages = ceil ((double )(npages /nIndexKeys ));
611
+ if ( nphack )
612
+ {
613
+ npages = fattr_select * ((Form_pg_class )GETSTRUCT (indRel ))-> relpages ;
614
+ * idxPages = ceil ((double )npages );
615
+ }
616
+ else
617
+ {
618
+ if ( nIndexKeys > 1 )
619
+ npages = npages / (1.0 + nIndexKeys );
620
+ * idxPages = ceil ((double )(npages /nIndexKeys ));
621
+ }
595
622
* idxSelec = select ;
596
623
}
597
624
0 commit comments