Skip to content

Exclude constants from grouping keys#2095

Merged
antepusic merged 15 commits intomasterfrom
no-constants-in-grouping_keys
Jun 25, 2024
Merged

Exclude constants from grouping keys#2095
antepusic merged 15 commits intomasterfrom
no-constants-in-grouping_keys

Conversation

@antepusic
Copy link
Contributor

@antepusic antepusic commented Jun 3, 2024

Exclude constants from grouping keys

@antepusic antepusic added bug bug Docs - changelog only Docs - changelog only CI -build=community -test=core Run community build and core tests on push CI -build=debug -test=core Run debug build and core tests on push CI -build=release -test=core Run release build and core tests on push labels Jun 3, 2024
@antepusic antepusic added this to the mg-v2.18.0 milestone Jun 3, 2024
@antepusic antepusic requested a review from Josipmrden June 3, 2024 19:33
@antepusic antepusic self-assigned this Jun 3, 2024
@antepusic antepusic linked an issue Jun 3, 2024 that may be closed by this pull request
@antoniofilipovic
Copy link
Contributor

@antepusic move description to comment section

@antepusic
Copy link
Contributor Author

antepusic commented Jun 24, 2024

Description

Context

If the following two conditions are met, the result of an aggregation is an empty set (cf. #1531):

  1. there’s no input to aggregate over
  2. results are returned grouped

Issue #1582 (the query MATCH (n:DoesNotExist) RETURN count(*) > 0 AS exists; returning an empty set) was caused by Memgraph mistakenly identifying the 0 constant as a grouping key.

Changes

This PR fixes the issue by excluding constants from the grouping keys, in line with Cypher:

For better query readability, Cypher only recognizes a sub-expression in aggregating expressions as a grouping key if the grouping key is either:

  • A variable - e.g. the p in RETURN p, p.age - max(f.age).
  • A property access - e.g. the p.age in RETURN p.age, p.age - max(f.age).
  • A map access - e.g. the p.age in WITH {name:'Keanu Reeves', age:58} AS p RETURN p.age, p.age - max(p.age).
    (from Neo4j docs)

[master < Task] PR

  • Provide the full content or a guide for the final git message

    Exclude constants from grouping keys

Documentation checklist

  • Add the documentation label tag
  • Add the bug / feature label tag
  • Add the milestone for which this feature is intended
  • Write a release note, including added/changed clauses

    Constant values aren’t used anymore to group the values going into aggregation functions. Exclude constants from grouping keys #2095

  • Link the documentation PR here (N/A – changelog only)
  • Tag someone from docs team in the comments

Copy link
Contributor

@antoniofilipovic antoniofilipovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment

@antepusic antepusic added the Ready for review PR is ready for review label Jun 24, 2024
@antepusic
Copy link
Contributor Author

@kgolubic Find the changelog entry in #2095 (comment)

@antepusic antepusic enabled auto-merge June 25, 2024 12:24
@sonarqubecloud
Copy link

@antepusic antepusic added this pull request to the merge queue Jun 25, 2024
@kgolubic
Copy link
Contributor

For release note I'll use:

  • Resolved an issue where constants were incorrectly used as grouping keys in aggregation queries.
    #2095

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 25, 2024
@antepusic antepusic added this pull request to the merge queue Jun 25, 2024
Merged via the queue into master with commit 181f3bc Jun 25, 2024
@antepusic antepusic deleted the no-constants-in-grouping_keys branch June 25, 2024 20:12
as51340 pushed a commit that referenced this pull request Oct 24, 2025
Exclude constants from grouping keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bug CI -build=community -test=core Run community build and core tests on push CI -build=debug -test=core Run debug build and core tests on push CI -build=release -test=core Run release build and core tests on push Docs - changelog only Docs - changelog only Ready for review PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query behavior changed: count(*)>0 on an empty set

3 participants