On Mon, Jan 20, 2014 at 2:43 PM, Alexander Korotkov <aekorot...@gmail.com> wrote: > Another changes in this version of patch: > 1) Applied patch to don't compare skipCols in tuplesort by Marti Raudsepp > 2) Adjusting sort bound after processing buckets.
Hi, Here's a patch with some whitespace and coding style fixes for partial-sort-6.patch I tried to understand the mergejoin regression, but this code still looks like Chinese to me. Can anyone else have a look at it? Test case: http://www.postgresql.org/message-id/cabrt9rdd-p2rlrdhsmq8rcob46k4a5o+bgz_up2brgeeh4r...@mail.gmail.com Original report: http://www.postgresql.org/message-id/CABRT9RCLLUyJ=bkeB132aVA_mVNx5==lvvvqmvuqdgufztw...@mail.gmail.com Regards, Marti
From a3cedb922c5a12e43ee94b9d6f5a2aefba701708 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp <ma...@juffo.org> Date: Sun, 26 Jan 2014 16:25:45 +0200 Subject: [PATCH 1/2] Whitespace & coding style fixes --- src/backend/executor/nodeSort.c | 17 +++++++++-------- src/backend/optimizer/path/costsize.c | 8 ++++---- src/backend/optimizer/path/pathkeys.c | 18 +++++++++--------- src/backend/optimizer/plan/createplan.c | 2 +- src/backend/optimizer/plan/planner.c | 6 +++--- src/backend/utils/sort/tuplesort.c | 2 +- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c index f38190d..2e50497 100644 --- a/src/backend/executor/nodeSort.c +++ b/src/backend/executor/nodeSort.c @@ -27,13 +27,14 @@ static bool cmpSortSkipCols(SortState *node, TupleDesc tupDesc, HeapTuple a, TupleTableSlot *b) { - int n = ((Sort *)node->ss.ps.plan)->skipCols, i; + int i, + n = ((Sort *)node->ss.ps.plan)->skipCols; for (i = 0; i < n; i++) { - Datum datumA, datumB; - bool isnullA, isnullB; - AttrNumber attno = node->skipKeys[i].ssup_attno; + Datum datumA, datumB; + bool isnullA, isnullB; + AttrNumber attno = node->skipKeys[i].ssup_attno; datumA = heap_getattr(a, attno, tupDesc, &isnullA); datumB = slot_getattr(b, attno, &isnullB); @@ -147,7 +148,7 @@ ExecSort(SortState *node) tuplesort_set_bound(tuplesortstate, node->bound - node->bound_Done); /* - * Put next group of tuples where skipCols" sort values are equal to + * Put next group of tuples where skipCols' sort values are equal to * tuplesort. */ for (;;) @@ -177,10 +178,10 @@ ExecSort(SortState *node) } else { - bool cmp; - cmp = cmpSortSkipCols(node, tupDesc, node->prev, slot); + bool equal; + equal = cmpSortSkipCols(node, tupDesc, node->prev, slot); node->prev = ExecCopySlotTuple(slot); - if (!cmp) + if (!equal) break; } } diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 9e79c6d..3a18632 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -1331,13 +1331,13 @@ cost_sort(Path *path, PlannerInfo *root, */ if (presorted_keys > 0) { - List *groupExprs = NIL; - ListCell *l; - int i = 0; + List *groupExprs = NIL; + ListCell *l; + int i = 0; foreach(l, pathkeys) { - PathKey *key = (PathKey *)lfirst(l); + PathKey *key = (PathKey *) lfirst(l); EquivalenceMember *member = (EquivalenceMember *) lfirst(list_head(key->pk_eclass->ec_members)); diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 55d8ef4..1e1a09a 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -319,10 +319,9 @@ compare_pathkeys(List *keys1, List *keys2) int pathkeys_common(List *keys1, List *keys2) { - int n; + int n = 0; ListCell *key1, *key2; - n = 0; forboth(key1, keys1, key2, keys2) { @@ -460,7 +459,7 @@ get_cheapest_fractional_path_for_pathkeys(List *paths, num_groups = (double *)palloc(sizeof(double) * list_length(pathkeys)); foreach(l, pathkeys) { - PathKey *key = (PathKey *)lfirst(l); + PathKey *key = (PathKey *) lfirst(l); EquivalenceMember *member = (EquivalenceMember *) lfirst(list_head(key->pk_eclass->ec_members)); @@ -1085,7 +1084,6 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root, List *mergeclauses = NIL; ListCell *i; bool *used = (bool *)palloc0(sizeof(bool) * list_length(restrictinfos)); - int k; List *unusedRestrictinfos = NIL; List *usedPathkeys = NIL; @@ -1103,6 +1101,7 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root, EquivalenceClass *pathkey_ec = pathkey->pk_eclass; List *matched_restrictinfos = NIL; ListCell *j; + int k = 0; /*---------- * A mergejoin clause matches a pathkey if it has the same EC. @@ -1140,7 +1139,6 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root, * deal with the case in create_mergejoin_plan(). *---------- */ - k = 0; foreach(j, restrictinfos) { RestrictInfo *rinfo = (RestrictInfo *) lfirst(j); @@ -1182,7 +1180,9 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root, */ if (outersortkeys) { - List *addPathkeys, *addMergeclauses; + List *addPathkeys, + *addMergeclauses; + int k = 0; *outersortkeys = pathkeys; @@ -1192,7 +1192,6 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root, /* * Find restrictions unused by given pathkeys. */ - k = 0; foreach(i, restrictinfos) { RestrictInfo *rinfo = (RestrictInfo *) lfirst(i); @@ -1208,7 +1207,8 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root, * Generate pathkeys based on those restrictions. */ addPathkeys = select_outer_pathkeys_for_merge(root, - unusedRestrictinfos, joinrel); + unusedRestrictinfos, + joinrel); if (!addPathkeys) return mergeclauses; @@ -1631,7 +1631,7 @@ right_merge_direction(PlannerInfo *root, PathKey *pathkey) static int pathkeys_useful_for_ordering(PlannerInfo *root, List *pathkeys) { - int n; + int n; if (root->query_pathkeys == NIL) return 0; /* no special ordering requested */ diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index d9a65c3..755f5e6 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -3744,7 +3744,7 @@ make_mergejoin(List *tlist, */ static Sort * make_sort(PlannerInfo *root, Plan *lefttree, int numCols, - List *pathkeys, int skipCols, + List *pathkeys, int skipCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst, double limit_tuples) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index e5cf5a8..0c3d18d 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -1763,7 +1763,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) int n_common_pathkeys; n_common_pathkeys = pathkeys_common(window_pathkeys, - current_pathkeys); + current_pathkeys); sort_plan = make_sort_from_pathkeys(root, result_plan, @@ -1946,8 +1946,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) */ if (parse->sortClause) { - int common = pathkeys_common(root->sort_pathkeys, current_pathkeys); - + int common = pathkeys_common(root->sort_pathkeys, current_pathkeys); + if (common < list_length(root->sort_pathkeys)) { result_plan = (Plan *) make_sort_from_pathkeys(root, diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index fb5d8b5..4a0ce29 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -949,7 +949,7 @@ tuplesort_end(Tuplesortstate *state) void tuplesort_reset(Tuplesortstate *state) { - int i; + int i; if (state->tapeset) LogicalTapeSetClose(state->tapeset); -- 1.8.5.3
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers