[−][src]Struct postgres_parser::nodes::SortGroupClause
SortGroupClause representation of ORDER BY, GROUP BY, PARTITION BY, DISTINCT, DISTINCT ON items
You might think that ORDER BY is only interested in defining ordering, and GROUP/DISTINCT are only interested in defining equality. However, one way to implement grouping is to sort and then apply a "uniq"like filter. So it's also interesting to keep track of possible sort operators for GROUP/DISTINCT, and in particular to try to sort for the grouping in a way that will also yield a requested ORDER BY ordering. So we need to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates the decision to give them the same representation.
tleSortGroupRef must match ressortgroupref of exactly one entry of the query's targetlist; that is the expression to be sorted or grouped by. eqop is the OID of the equality operator. sortop is the OID of the ordering operator (a "<" or ">" operator), or InvalidOid if not available. nulls_first means about what you'd expect. If sortop is InvalidOid then nulls_first is meaningless and should be set to false. hashable is true if eqop is hashable (note this condition also depends on the datatype of the input expression).
In an ORDER BY item, all fields must be valid. (The eqop isn't essential here, but it's cheap to get it along with the sortop, and requiring it to be valid eases comparisons to grouping items.) Note that this isn't actually enough information to determine an ordering: if the sortop is collationsensitive, a collation OID is needed too. We don't store the collation in SortGroupClause because it's not available at the time the parser builds the SortGroupClause; instead, consult the exposed collation of the referenced targetlist expression to find out what it is.
In a grouping item, eqop must be valid. If the eqop is a btree equality operator, then sortop should be set to a compatible ordering operator. We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that the query presents for the same tlist item. If there is none, we just use the default ordering op for the datatype.
If the tlist item's type has a hash opclass but no btree opclass, then we will set eqop to the hash equality operator, sortop to InvalidOid, and nulls_first to false. A grouping item of this kind can only be implemented by hashing, and of course it'll never match an ORDER BY item.
The hashable flag is provided since we generally have the requisite information readily available when the SortGroupClause is constructed, and it's relatively expensive to get it again later. Note there is no need for a "sortable" flag since OidIsValid(sortop) serves the purpose.
A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses. In SELECT DISTINCT, the distinctClause list is as long or longer than the sortClause list, while in SELECT DISTINCT ON it's typically shorter. The two lists must match up to the end of the shorter one the parser rearranges the distinctClause if necessary to make this true. (This restriction ensures that only one sort step is needed to both satisfy the ORDER BY and set up for the Unique step. This is semantically necessary for DISTINCT ON, and presents no real drawback for DISTINCT.)
Fields
tleSortGroupRef: Index
eqop: Oid
sortop: Oid
nulls_first: bool
hashable: bool
Trait Implementations
impl Debug for SortGroupClause
[src]
impl<'de> Deserialize<'de> for SortGroupClause
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Eq for SortGroupClause
[src]
impl PartialEq<SortGroupClause> for SortGroupClause
[src]
fn eq(&self, other: &SortGroupClause) -> bool
[src]
fn ne(&self, other: &SortGroupClause) -> bool
[src]
impl Serialize for SortGroupClause
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for SortGroupClause
[src]
impl StructuralPartialEq for SortGroupClause
[src]
Auto Trait Implementations
impl RefUnwindSafe for SortGroupClause
impl Send for SortGroupClause
impl Sync for SortGroupClause
impl Unpin for SortGroupClause
impl UnwindSafe for SortGroupClause
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,