~ubuntu-branches/ubuntu/trusty/postgresql-8.4/trusty

« back to all changes in this revision

Viewing changes to src/backend/optimizer/prep/prepunion.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 *
23
23
 *
24
24
 * IDENTIFICATION
25
 
 *        $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.170 2009/05/12 03:11:01 tgl Exp $
 
25
 *        $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.171 2009/06/11 14:48:59 momjian Exp $
26
26
 *
27
27
 *-------------------------------------------------------------------------
28
28
 */
97
97
                                                  Index newvarno,
98
98
                                                  List **translated_vars);
99
99
static Bitmapset *translate_col_privs(const Bitmapset *parent_privs,
100
 
                                                                          List *translated_vars);
 
100
                                        List *translated_vars);
101
101
static Node *adjust_appendrel_attrs_mutator(Node *node,
102
102
                                                           AppendRelInfo *context);
103
103
static Relids adjust_relid_set(Relids relids, Index oldrelid, Index newrelid);
220
220
                                                                   &subroot);
221
221
 
222
222
                /*
223
 
                 * Estimate number of groups if caller wants it.  If the subquery
224
 
                 * used grouping or aggregation, its output is probably mostly
225
 
                 * unique anyway; otherwise do statistical estimation.
 
223
                 * Estimate number of groups if caller wants it.  If the subquery used
 
224
                 * grouping or aggregation, its output is probably mostly unique
 
225
                 * anyway; otherwise do statistical estimation.
226
226
                 */
227
227
                if (pNumGroups)
228
228
                {
231
231
                                *pNumGroups = subplan->plan_rows;
232
232
                        else
233
233
                                *pNumGroups = estimate_num_groups(subroot,
234
 
                                                                                                  get_tlist_exprs(subquery->targetList, false),
 
234
                                                                get_tlist_exprs(subquery->targetList, false),
235
235
                                                                                                  subplan->plan_rows);
236
236
                }
237
237
 
361
361
        }
362
362
        else
363
363
        {
364
 
                double  dNumGroups;
 
364
                double          dNumGroups;
365
365
 
366
366
                /* Identify the grouping semantics */
367
367
                groupList = generate_setop_grouplist(setOp, tlist);
374
374
                                         errdetail("All column datatypes must be hashable.")));
375
375
 
376
376
                /*
377
 
                 * For the moment, take the number of distinct groups as equal to
378
 
                 * the total input size, ie, the worst case.
 
377
                 * For the moment, take the number of distinct groups as equal to the
 
378
                 * total input size, ie, the worst case.
379
379
                 */
380
380
                dNumGroups = lplan->plan_rows + rplan->plan_rows * 10;
381
381
 
460
460
                plan = make_union_unique(op, plan, root, tuple_fraction, sortClauses);
461
461
 
462
462
        /*
463
 
         * Estimate number of groups if caller wants it.  For now we just
464
 
         * assume the output is unique --- this is certainly true for the
465
 
         * UNION case, and we want worst-case estimates anyway.
 
463
         * Estimate number of groups if caller wants it.  For now we just assume
 
464
         * the output is unique --- this is certainly true for the UNION case, and
 
465
         * we want worst-case estimates anyway.
466
466
         */
467
467
        if (pNumGroups)
468
468
                *pNumGroups = plan->plan_rows;
555
555
         * Estimate number of distinct groups that we'll need hashtable entries
556
556
         * for; this is the size of the left-hand input for EXCEPT, or the smaller
557
557
         * input for INTERSECT.  Also estimate the number of eventual output rows.
558
 
         * In non-ALL cases, we estimate each group produces one output row;
559
 
         * in ALL cases use the relevant relation size.  These are worst-case
 
558
         * In non-ALL cases, we estimate each group produces one output row; in
 
559
         * ALL cases use the relevant relation size.  These are worst-case
560
560
         * estimates, of course, but we need to be conservative.
561
561
         */
562
562
        if (op->op == SETOP_EXCEPT)
578
578
         */
579
579
        use_hash = choose_hashed_setop(root, groupList, plan,
580
580
                                                                   dNumGroups, dNumOutputRows, tuple_fraction,
581
 
                                                                   (op->op == SETOP_INTERSECT) ? "INTERSECT" : "EXCEPT");
 
581
                                           (op->op == SETOP_INTERSECT) ? "INTERSECT" : "EXCEPT");
582
582
 
583
583
        if (!use_hash)
584
584
                plan = (Plan *) make_sort_from_sortclauses(root, groupList, plan);
687
687
        }
688
688
 
689
689
        /*
690
 
         * XXX for the moment, take the number of distinct groups as equal to
691
 
         * the total input size, ie, the worst case.  This is too conservative,
692
 
         * but we don't want to risk having the hashtable overrun memory; also,
693
 
         * it's not clear how to get a decent estimate of the true size.  One
694
 
         * should note as well the propensity of novices to write UNION rather
695
 
         * than UNION ALL even when they don't expect any duplicates...
 
690
         * XXX for the moment, take the number of distinct groups as equal to the
 
691
         * total input size, ie, the worst case.  This is too conservative, but we
 
692
         * don't want to risk having the hashtable overrun memory; also, it's not
 
693
         * clear how to get a decent estimate of the true size.  One should note
 
694
         * as well the propensity of novices to write UNION rather than UNION ALL
 
695
         * even when they don't expect any duplicates...
696
696
         */
697
697
        dNumGroups = plan->plan_rows;
698
698
 
763
763
        else
764
764
                ereport(ERROR,
765
765
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
766
 
                                 /* translator: %s is UNION, INTERSECT, or EXCEPT */
 
766
                /* translator: %s is UNION, INTERSECT, or EXCEPT */
767
767
                                 errmsg("could not implement %s", construct),
768
768
                                 errdetail("Some of the datatypes only support hashing, while others only support sorting.")));
769
769
 
1260
1260
                appinfos = lappend(appinfos, appinfo);
1261
1261
 
1262
1262
                /*
1263
 
                 * Translate the column permissions bitmaps to the child's attnums
1264
 
                 * (we have to build the translated_vars list before we can do this).
1265
 
                 * But if this is the parent table, leave copyObject's result alone.
 
1263
                 * Translate the column permissions bitmaps to the child's attnums (we
 
1264
                 * have to build the translated_vars list before we can do this). But
 
1265
                 * if this is the parent table, leave copyObject's result alone.
1266
1266
                 */
1267
1267
                if (childOID != parentOID)
1268
1268
                {
1269
1269
                        childrte->selectedCols = translate_col_privs(rte->selectedCols,
1270
 
                                                                                                                 appinfo->translated_vars);
 
1270
                                                                                                   appinfo->translated_vars);
1271
1271
                        childrte->modifiedCols = translate_col_privs(rte->modifiedCols,
1272
 
                                                                                                                 appinfo->translated_vars);
 
1272
                                                                                                   appinfo->translated_vars);
1273
1273
                }
1274
1274
 
1275
1275
                /*
1420
1420
 *        parent rel's attribute numbering to the child's.
1421
1421
 *
1422
1422
 * The only surprise here is that we don't translate a parent whole-row
1423
 
 * reference into a child whole-row reference.  That would mean requiring
 
1423
 * reference into a child whole-row reference.  That would mean requiring
1424
1424
 * permissions on all child columns, which is overly strict, since the
1425
1425
 * query is really only going to reference the inherited columns.  Instead
1426
1426
 * we set the per-column bits for all inherited columns.
1435
1435
        ListCell   *lc;
1436
1436
 
1437
1437
        /* System attributes have the same numbers in all tables */
1438
 
        for (attno = FirstLowInvalidHeapAttributeNumber+1; attno < 0; attno++)
 
1438
        for (attno = FirstLowInvalidHeapAttributeNumber + 1; attno < 0; attno++)
1439
1439
        {
1440
1440
                if (bms_is_member(attno - FirstLowInvalidHeapAttributeNumber,
1441
1441
                                                  parent_privs))
1442
1442
                        child_privs = bms_add_member(child_privs,
1443
 
                                                                                 attno - FirstLowInvalidHeapAttributeNumber);
 
1443
                                                                 attno - FirstLowInvalidHeapAttributeNumber);
1444
1444
        }
1445
1445
 
1446
1446
        /* Check if parent has whole-row reference */
1451
1451
        attno = InvalidAttrNumber;
1452
1452
        foreach(lc, translated_vars)
1453
1453
        {
1454
 
                Var        *var = (Var *) lfirst(lc);
 
1454
                Var                *var = (Var *) lfirst(lc);
1455
1455
 
1456
1456
                attno++;
1457
1457
                if (var == NULL)                /* ignore dropped columns */
1461
1461
                        bms_is_member(attno - FirstLowInvalidHeapAttributeNumber,
1462
1462
                                                  parent_privs))
1463
1463
                        child_privs = bms_add_member(child_privs,
1464
 
                                                                                 var->varattno - FirstLowInvalidHeapAttributeNumber);
 
1464
                                                 var->varattno - FirstLowInvalidHeapAttributeNumber);
1465
1465
        }
1466
1466
 
1467
1467
        return child_privs;