Skip to content

Cypher : fix profile and explain corrupting returned values#3406

Merged
lvca merged 3 commits intoArcadeData:mainfrom
ExtReMLapin:explian_profile_fix
Feb 11, 2026
Merged

Cypher : fix profile and explain corrupting returned values#3406
lvca merged 3 commits intoArcadeData:mainfrom
ExtReMLapin:explian_profile_fix

Conversation

@ExtReMLapin
Copy link
Contributor

@ExtReMLapin ExtReMLapin commented Feb 11, 2026

What does this PR do?

Fixes #3405

Before this fix, using with cypher EXPLAIN or PROFILE was not storing anything in the dedicated REST fields.

It was storing the profile or explain result in the records fields, mixing up with the data returned from the query.

Using profile was even "leaking" data that was never asked to be returned.

claude wrote all the code, I just tested it

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ExtReMLapin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical issues with how Cypher's EXPLAIN and PROFILE commands interact with the system's result handling and REST API. The changes ensure that execution plan information is correctly formatted and delivered in dedicated fields, preventing unintended data exposure and improving the accuracy of query profiling. This significantly enhances the debugging and performance analysis capabilities for Cypher queries.

Highlights

  • Cypher EXPLAIN/PROFILE Output Fix: Resolved an issue where Cypher's EXPLAIN and PROFILE commands were not correctly populating dedicated REST fields in the server response, leading to missing or corrupted output.
  • Data Leak Prevention in PROFILE: Fixed a bug in the PROFILE command that caused it to 'leak' data that was not explicitly requested, ensuring that PROFILE now only returns profiling information and the actual query results.
  • Standardized Execution Plan Handling: Introduced a new OpenCypherExplainExecutionPlan class and utilized ExplainResultSet to standardize how execution plan details (for both EXPLAIN and PROFILE) are encapsulated and returned, especially for HTTP responses.
  • Updated Test Suite: Modified existing OpenCypher optimizer and profile tests to align with the new mechanism for retrieving execution plan details, ensuring the fixes behave as expected.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • engine/src/main/java/com/arcadedb/query/opencypher/executor/CypherExecutionPlan.java
    • Updated imports to include InternalResultSet and ExplainResultSet.
    • Refactored explain() method to return an ExplainResultSet containing the execution plan string.
    • Modified profile() method to collect actual query results into an InternalResultSet for row counting, then discard them, and return profiling information via an ExplainResultSet.
  • engine/src/main/java/com/arcadedb/query/opencypher/executor/OpenCypherExplainExecutionPlan.java
    • Added new class OpenCypherExplainExecutionPlan to encapsulate explain/profile text as an ExecutionPlan.
  • engine/src/test/java/com/arcadedb/query/opencypher/OpenCypherOptimizerVerificationTest.java
    • Updated multiple test methods to retrieve the explain plan using explainResult.getExecutionPlan().get().prettyPrint() instead of explainResult.next().getProperty("plan").
  • engine/src/test/java/com/arcadedb/query/opencypher/OpenCypherUnionCallProfileTest.java
    • Adjusted profileBasic() and profileShowsRowCount() tests to fetch profile details from the execution plan and verify that actual query results are still returned.
    • Modified explainDoesNotExecute() test to retrieve the explain plan from getExecutionPlan() and confirm the ExplainResultSet behavior.
  • server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java
    • Added import for ExplainResultSet.
    • Modified execute method to specifically handle ExplainResultSet by extracting the explain text, draining the result set, and populating the 'explain' field in the JSON response.
Activity
  • The pull request author, ExtReMLapin, tested the code which was primarily written by 'claude'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issues with EXPLAIN and PROFILE in Cypher queries. The changes correctly utilize ExplainResultSet for EXPLAIN and attach profiling information as an execution plan for PROFILE, which prevents corrupting the result set. The new OpenCypherExplainExecutionPlan class is a clean way to wrap the plan text. The test updates are thorough and correctly reflect the new behavior. I've added a few suggestions to improve code clarity, consistency, and documentation in the new implementation.

Comment on lines 353 to 360
* Executes the query with profiling enabled.
* Returns the query results along with execution metrics.
* The query is executed to collect real metrics, but only the profiling
* information is returned (actual query results are discarded).
* Returns an {@link ExplainResultSet} so the server handler populates the
* dedicated {@code explain} field in the JSON response.
*
* @return result set containing results and profiling metrics
* @return result set containing profiling metrics via {@code getExecutionPlan()}
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Javadoc for the profile() method is misleading. It incorrectly states that query results are discarded and that an ExplainResultSet is returned. The implementation actually returns the query results in an InternalResultSet, with profiling information attached as an execution plan. Please update the documentation to reflect the actual behavior.

   /**
    * Executes the query with profiling enabled.
    * Returns the query results along with execution metrics. The profiling information
    * is available via {@link com.arcadedb.query.sql.executor.ResultSet#getExecutionPlan()}.
    *
    * @return a result set containing the query results, with profiling metrics available in the execution plan.
    */

Comment on lines +378 to +379
while (resultSet.hasNext())
results.add(resultSet.next());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While syntactically correct, using while loops without braces can be error-prone. If another statement is added to the loop body in the future without adding braces, it will execute outside the loop, potentially causing bugs. It's safer to always use braces for clarity and to prevent future errors.

        while (resultSet.hasNext()) {
          results.add(resultSet.next());
        }

Comment on lines 383 to 389
final boolean hasWithBeforeMatch2 = hasWithPrecedingMatch();

final boolean hasVLP2 = hasVariableLengthPath();
if (physicalPlan != null && physicalPlan.getRootOperator() != null && !hasUnwindBeforeMatch && !hasWithBeforeMatch2 && !hasVLP2) {
if (physicalPlan != null && physicalPlan.getRootOperator() != null && !hasUnwindBeforeMatch && !hasWithBeforeMatch2 && !hasVLP2)
rootStep = buildExecutionStepsWithOptimizer(context);
} else {
else
rootStep = buildExecutionSteps(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There are a couple of issues in this block that affect readability and maintainability:

  1. The local variables hasWithBeforeMatch2 and hasVLP2 use a 2 suffix, which is inconsistent with similarly named variables in the execute() method. This seems to be a copy-paste artifact.
  2. The if-else statement lacks braces, which is generally discouraged for safety and consistency.

I'd suggest renaming the variables and adding braces.

        final boolean hasWithBeforeMatch = hasWithPrecedingMatch();

        final boolean hasVLP = hasVariableLengthPath();
        if (physicalPlan != null && physicalPlan.getRootOperator() != null && !hasUnwindBeforeMatch && !hasWithBeforeMatch && !hasVLP) {
          rootStep = buildExecutionStepsWithOptimizer(context);
        } else {
          rootStep = buildExecutionSteps(context);
        }

…andHandler.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@lvca lvca self-requested a review February 11, 2026 17:48
@lvca
Copy link
Member

lvca commented Feb 11, 2026

Awesome, thanks!

@lvca lvca merged commit b4b5a7c into ArcadeData:main Feb 11, 2026
10 of 14 checks passed
@lvca lvca added this to the 26.2.1 milestone Feb 11, 2026
@mergify
Copy link
Contributor

mergify bot commented Feb 11, 2026

🧪 CI Insights

Here's what we observed from your CI run for 754ff84.

🟢 All jobs passed!

But CI Insights is watching 👀

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 51.42857% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.63%. Comparing base (69dc8d4) to head (754ff84).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...cadedb/server/http/handler/PostCommandHandler.java 9.09% 7 Missing and 3 partials ⚠️
...query/opencypher/executor/CypherExecutionPlan.java 60.00% 4 Missing and 2 partials ⚠️
...ypher/executor/OpenCypherExplainExecutionPlan.java 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3406      +/-   ##
==========================================
+ Coverage   62.12%   62.63%   +0.51%     
==========================================
  Files        1249     1250       +1     
  Lines       84354    84359       +5     
  Branches    17312    17316       +4     
==========================================
+ Hits        52406    52840     +434     
+ Misses      24639    24241     -398     
+ Partials     7309     7278      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

robfrank pushed a commit that referenced this pull request Feb 17, 2026
* fix explain and profile

* Fixed profile blocking data return

* Update server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: Pierre F <no@p.e>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
(cherry picked from commit b4b5a7c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cypher : Weird behavior with PROFILE & EXPLAIN, returned in first row entry

2 participants