Skip to content

Conversation

Tony2h
Copy link
Contributor

@Tony2h Tony2h commented Oct 13, 2025

Description

Please briefly describe the code changes in this pull request.

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copy link
Contributor

Summary of Changes

Hello @Tony2h, 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 enhances the database query optimizer's logic for aggregate functions, specifically addressing how the LAST function interacts with non-primary key columns, particularly in the context of composite keys. The changes ensure that the optimizer correctly identifies and processes these columns, and new comprehensive test cases have been added to validate this improved behavior.

Highlights

  • Query Optimizer Logic Update: Modified the lastRowScanOptCheckFuncList in planOptimizer.c to include a check for non-primary key columns (!pCol->isPk) when processing SELECT_VALUE functions, ensuring correct handling of aggregate functions.
  • New Test Cases for LAST function: Added a new test method test_last_pk in test_agg_last.py to specifically validate the behavior of the LAST aggregate function when used with composite keys.
  • Test Resources Added: Included new resource files, last_pk.in and last_pk.csv, which define the input SQL queries and their expected outputs for the test_last_pk test case.
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 enhances the query optimizer to correctly apply the Last Row Scan optimization for queries that use the last() function on a timestamp column while also selecting a composite primary key column. The fix in planOptimizer.c ensures that composite key columns are not incorrectly identified as non-primary key columns, which previously blocked this optimization. A new Python test case, test_last_pk, has been added to validate this change, including EXPLAIN queries to confirm that the Last Row Scan is utilized as expected. The changes are logical and the accompanying test is thorough and relevant.

@Tony2h Tony2h changed the title Enh/3.0/td 38004 enh(last): enable using cache when select last and composite key Oct 13, 2025
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Tony Zhang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@guanshengliang guanshengliang merged commit f168881 into main Oct 14, 2025
13 of 17 checks passed
@Tony2h Tony2h deleted the enh/3.0/TD-38004 branch October 17, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants