Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
47f18ec7
Commit
47f18ec7
authored
Aug 13, 1999
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comments about pathkeys.
parent
8f9f6e51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
28 deletions
+63
-28
src/backend/optimizer/path/pathkeys.c
src/backend/optimizer/path/pathkeys.c
+63
-28
No files found.
src/backend/optimizer/path/pathkeys.c
View file @
47f18ec7
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.1
2 1999/07/16 04:59:15 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.1
3 1999/08/13 01:17:16 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -33,18 +33,24 @@ static List *new_join_pathkey(List *pathkeys, List *join_rel_tlist,
...
@@ -33,18 +33,24 @@ static List *new_join_pathkey(List *pathkeys, List *join_rel_tlist,
* order of the result generated by the Path.
* order of the result generated by the Path.
*
*
* In single/base relation RelOptInfo's, the Path's represent various ways
* In single/base relation RelOptInfo's, the Path's represent various ways
* of
generat
ing the relation and the resulting ordering of the tuples.
* of
scann
ing the relation and the resulting ordering of the tuples.
* Sequential scan Paths have NIL pathkeys, indicating no known ordering.
* Sequential scan Paths have NIL pathkeys, indicating no known ordering.
* Index scans have Path.pathkeys that represent the chosen index.
* Index scans have Path.pathkeys that represent the chosen index's ordering,
* A single-key index pathkeys would be { {tab1_indexkey1} }. For a
* if any. A single-key index would create a pathkey with a single sublist,
* multi-key index pathkeys would be { {tab1_indexkey1}, {tab1_indexkey2} },
* e.g. ( (tab1_indexkey1) ). A multi-key index generates a sublist per key,
* indicating major sort by indexkey1 and minor sort by indexkey2.
* e.g. ( (tab1_indexkey1) (tab1_indexkey2) ) which shows major sort by
* indexkey1 and minor sort by indexkey2.
*
* Note that a multi-pass indexscan (OR clause scan) has NIL pathkeys since
* we can say nothing about the overall order of its result. Also, an index
* scan on an unordered type of index generates no useful pathkeys. However,
* we can always create a pathkey by doing an explicit sort.
*
*
* Multi-relation RelOptInfo Path's are more complicated. Mergejoins are
* Multi-relation RelOptInfo Path's are more complicated. Mergejoins are
* only performed with equijoins ("="). Because of this, the multi-relation
* only performed with equijoins ("="). Because of this, the multi-relation
* path actually has more than one primary Var key. For example, a
* path actually has more than one primary Var key. For example, a
* mergejoin Path of "tab1.col1 = tab2.col1" would generate
a
pathkeys of
* mergejoin Path of "tab1.col1 = tab2.col1" would generate pathkeys of
*
{ {tab1.col1, tab2.col1} }
, indicating that the major sort order of the
*
( (tab1.col1 tab2.col1) )
, indicating that the major sort order of the
* Path can be taken to be *either* tab1.col1 or tab2.col1.
* Path can be taken to be *either* tab1.col1 or tab2.col1.
* They are equal, so they are both primary sort keys. This allows future
* They are equal, so they are both primary sort keys. This allows future
* joins to use either Var as a pre-sorted key to prevent upper Mergejoins
* joins to use either Var as a pre-sorted key to prevent upper Mergejoins
...
@@ -53,21 +59,30 @@ static List *new_join_pathkey(List *pathkeys, List *join_rel_tlist,
...
@@ -53,21 +59,30 @@ static List *new_join_pathkey(List *pathkeys, List *join_rel_tlist,
* Note that while the order of the top list is meaningful (primary vs.
* Note that while the order of the top list is meaningful (primary vs.
* secondary sort key), the order of each sublist is arbitrary.
* secondary sort key), the order of each sublist is arbitrary.
*
*
* For multi-key sorts, if the outer is sorted by a multi-key index, the
* We can actually keep all of the keys of the outer path of a merge or
* multi-key index remains after the join. If the inner has a multi-key
* nestloop join, since the ordering of the outer path will be reflected
* sort, only the primary key of the inner is added to the result.
* in the result. We add to each pathkey sublist any inner vars that are
* Mergejoins only join on the primary key. Currently, non-primary keys
* equijoined to any of the outer vars in the sublist. In the nestloop
* in the pathkeys List are of limited value.
* case we have to be careful to consider only equijoin operators; the
* nestloop's join clauses might include non-equijoin operators.
* (Currently, we do this by considering only mergejoinable operators while
* making the pathkeys, since we have no separate marking for operators that
* are equijoins but aren't mergejoinable.)
*
*
* Although Hashjoins also work only with equijoin operators, it is *not*
* Although Hashjoins also work only with equijoin operators, it is *not*
* safe to consider the output of a Hashjoin to be sorted in any particular
* safe to consider the output of a Hashjoin to be sorted in any particular
* order --- not even the outer path's order. This is true because the
* order --- not even the outer path's order. This is true because the
* executor might have to split the join into multiple batches.
* executor might have to split the join into multiple batches. Therefore
* a Hashjoin is always given NIL pathkeys.
*
*
* NestJoin does not perform sorting, and allows non-equijoins, so it does
* Notice that pathkeys only say *what* is being ordered, and not *how*
* not allow useful pathkeys. (But couldn't we use the outer path's order?)
* it is ordered. The actual sort ordering is indicated by a separate
* data structure, the PathOrder. The PathOrder provides a sort operator
* OID for each of the sublists of the path key. This is fairly bogus,
* since in cross-datatype cases we really want to keep track of more than
* one sort operator...
*
*
* -- bjm
* -- bjm
& tgl
*--------------------
*--------------------
*/
*/
...
@@ -328,17 +343,32 @@ make_pathkeys_from_joinkeys(List *joinkeys,
...
@@ -328,17 +343,32 @@ make_pathkeys_from_joinkeys(List *joinkeys,
/*
/*
* new_join_pathkeys
* new_join_pathkeys
* Find the path keys for a join relation by finding all vars in the list
* Build the path keys for a join relation constructed by mergejoin or
* of join clauses 'joinclauses' such that:
* nestloop join. These keys should include all the path key vars of the
* (1) the var corresponding to the outer join relation is a
* outer path (since the join will retain the ordering of the outer path)
* key on the outer path
* plus any vars of the inner path that are mergejoined to the outer vars.
* (2) the var appears in the target list of the join relation
*
* In other words, add to each outer path key the inner path keys that
* Per the discussion at the top of this file, mergejoined inner vars
* are required for qualification.
* can be considered path keys of the result, just the same as the outer
* vars they were joined with.
*
* We can also use inner path vars as pathkeys of a nestloop join, but we
* must be careful that we only consider equijoin clauses and not general
* join clauses. For example, "t1.a < t2.b" might be a join clause of a
* nestloop, but it doesn't result in b acquiring the ordering of a!
* joinpath.c handles that problem by only passing this routine clauses
* that are marked mergejoinable, even if a nestloop join is being built.
* Therefore we only have 't1.a = t2.b' style clauses, and can expect that
* the inner var will acquire the outer's ordering no matter which join
* method is actually used.
*
* All vars in the result are copied from the join relation's tlist, not from
* the given pathkeys or the join clauses. (Is that necessary? I suspect
* not --- tgl)
*
*
* 'outer_pathkeys' is the list of the outer path's path keys
* 'outer_pathkeys' is the list of the outer path's path keys
* 'join_rel_tlist' is the target list of the join relation
* 'join_rel_tlist' is the target list of the join relation
* 'joinclauses' is the list of
restricting
join clauses
* 'joinclauses' is the list of
mergejoinable
join clauses
*
*
* Returns the list of new path keys.
* Returns the list of new path keys.
*
*
...
@@ -358,8 +388,13 @@ new_join_pathkeys(List *outer_pathkeys,
...
@@ -358,8 +388,13 @@ new_join_pathkeys(List *outer_pathkeys,
new_pathkey
=
new_join_pathkey
(
outer_pathkey
,
join_rel_tlist
,
new_pathkey
=
new_join_pathkey
(
outer_pathkey
,
join_rel_tlist
,
joinclauses
);
joinclauses
);
if
(
new_pathkey
!=
NIL
)
/* if we can find no sortable vars for the n'th sort key,
final_pathkeys
=
lappend
(
final_pathkeys
,
new_pathkey
);
* then we're done generating pathkeys; can't expect to order
* subsequent vars. Not clear that this can really happen.
*/
if
(
new_pathkey
==
NIL
)
break
;
final_pathkeys
=
lappend
(
final_pathkeys
,
new_pathkey
);
}
}
return
final_pathkeys
;
return
final_pathkeys
;
}
}
...
@@ -372,7 +407,7 @@ new_join_pathkeys(List *outer_pathkeys,
...
@@ -372,7 +407,7 @@ new_join_pathkeys(List *outer_pathkeys,
* at the top of this file).
* at the top of this file).
*
*
* Note that each returned pathkey is the var node found in
* Note that each returned pathkey is the var node found in
* 'join_rel_tlist' rather than the joinclause var node.
* 'join_rel_tlist' rather than the
input pathkey or
joinclause var node.
* (Is this important?) Also, we return a fully copied list
* (Is this important?) Also, we return a fully copied list
* that does not share any subnodes with existing data structures.
* that does not share any subnodes with existing data structures.
* (Is that important, either?)
* (Is that important, either?)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment