77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.49 1999/07/27 03:51:05 tgl Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.50 1999/07/30 00:56:17 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -329,11 +329,16 @@ create_index_path(Query *root,
329329
330330/* Note that we are making a pathnode for a single-scan indexscan;
331331 * therefore, both indexid and indexqual should be single-element
332- * lists (unless indexqual is empty).
332+ * lists. We initialize indexqual to contain one empty sublist,
333+ * representing a single index traversal with no index restriction
334+ * conditions. If we do have restriction conditions to use, they
335+ * will get inserted below.
333336 */
337+ Assert (length (index -> relids )== 1 );
334338pathnode -> indexid = index -> relids ;
339+ pathnode -> indexqual = lcons (NIL ,NIL );
340+
335341pathnode -> indexkeys = index -> indexkeys ;
336- pathnode -> indexqual = NIL ;
337342
338343/*
339344 * The index must have an ordering for the path to have (ordering)
@@ -358,14 +363,19 @@ create_index_path(Query *root,
358363
359364if (is_join_scan || restriction_clauses == NULL )
360365{
361-
362366/*
363367 * Indices used for joins or sorting result nodes don't restrict
364368 * the result at all, they simply order it, so compute the scan
365369 * cost accordingly -- use a selectivity of 1.0.
370+ *
371+ * is the statement above really true?what about IndexScan as the
372+ * inner of a join?
373+ *
374+ * I think it's OK --- this routine is only used to make index paths
375+ * for mergejoins and sorts. Index paths used as the inner side of
376+ * a nestloop join do provide restriction, but they are not made
377+ * with this code. See index_innerjoin() in indxpath.c.
366378 */
367- /* is the statement above really true?what about IndexScan as the
368- inner of a join? */
369379pathnode -> path .path_cost = cost_index (lfirsti (index -> relids ),
370380index -> pages ,
3713811.0 ,
@@ -378,8 +388,8 @@ create_index_path(Query *root,
378388else
379389{
380390/*
381- * Compute scan cost for the case when 'index' is used with a
382- * restriction clause.
391+ * Compute scan cost for the case when 'index' is used with
392+ * restriction clause(s) .
383393 */
384394List * indexquals ;
385395float npages ;
@@ -390,14 +400,18 @@ create_index_path(Query *root,
390400/* expand special operators to indexquals the executor can handle */
391401indexquals = expand_indexqual_conditions (indexquals );
392402
403+ /* Insert qual list into 1st sublist of pathnode->indexqual;
404+ * we already made the cons cell above, no point in wasting it...
405+ */
406+ lfirst (pathnode -> indexqual )= indexquals ;
407+
393408index_selectivity (root ,
394409lfirsti (rel -> relids ),
395410lfirsti (index -> relids ),
396411indexquals ,
397412& npages ,
398413& selec );
399414
400- pathnode -> indexqual = lcons (indexquals ,NIL );
401415pathnode -> path .path_cost = cost_index (lfirsti (index -> relids ),
402416 (int )npages ,
403417selec ,