Skip to content

Conversation

@DvdGiessen
Copy link

@DvdGiessen DvdGiessen commented Mar 26, 2025

Description

To be able to use the MySQL foreign data wrapper for PostgreSQL, we have to support server side cursors.

To that end each connection now keeps track of a list of open cursors, and implements the COM_STMT_FETCH command for retrieving data from an open cursor.

Based on the implementation in the Dolthub fork of Vitess:

Compared to the implementation in the Dolthub fork this commit:

  • Was changed to fit with all changes made in Vitess since the Dolthub version was forked
  • Remove a few superfluous formatting/whitespace changes made in there to make reviewing easier.
  • Also supports multiple open cursors whereas the Dolthub fork only supports a single open cursor.

I've also moved all the changes to other code (namely, updating them to use the "status" integer instead of the old "more" boolean) into a separate commit to make it easier to review.

Related Issue(s)

#18046

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

This only implements a new protocol feature and does not affect any on-disk information. No migrations should be required.

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Mar 26, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Mar 26, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Mar 26, 2025
@DvdGiessen DvdGiessen marked this pull request as ready for review March 26, 2025 14:10
@DvdGiessen DvdGiessen force-pushed the server-side-cursors branch from 20d5d8f to 5b481d5 Compare March 26, 2025 14:19
@DvdGiessen
Copy link
Author

Re-pushed with updated commit description because I just noticed I misattributed some of the original work this change is based on (I copied the author from a wrong commit). Want to make sure I give credit where it's due. (:

@frouioui frouioui modified the milestones: v22.0.0, v23.0.0 Apr 1, 2025
@DvdGiessen DvdGiessen force-pushed the server-side-cursors branch from 5b481d5 to ba5ef51 Compare April 15, 2025 14:16
@github-actions
Copy link
Contributor

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label May 16, 2025
@DvdGiessen DvdGiessen force-pushed the server-side-cursors branch 2 times, most recently from 850cfef to bbf12b9 Compare May 16, 2025 09:22
@github-actions github-actions bot removed the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label May 17, 2025
@DvdGiessen DvdGiessen force-pushed the server-side-cursors branch from bbf12b9 to 58fffbd Compare May 21, 2025 16:58
Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

You would need to add e2e test to validate it works cleanly with fdw

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2025

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Jul 3, 2025
@DvdGiessen DvdGiessen force-pushed the server-side-cursors branch from 58fffbd to 55d0b81 Compare July 10, 2025 00:21
@github-actions github-actions bot removed the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Jul 10, 2025
@harshit-gangal harshit-gangal self-assigned this Jul 30, 2025
@harshit-gangal
Copy link
Member

There are some CI failures that needs to be addressed.

@harshit-gangal harshit-gangal self-requested a review July 30, 2025 13:46
@github-actions
Copy link
Contributor

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. and removed Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. labels Aug 30, 2025
@DvdGiessen
Copy link
Author

You would need to add e2e test to validate it works cleanly with fdw

I agree a E2E test for this would be useful to prevent this from breaking in the future.

However, I'm not entirely sure how to go about implementing this E2E test within the template structure used for generating the workflows. I'd very much welcome if anyone else wants to help contribute such a test!

The basic test would work like this:

  • Create some tables in Vitess which we want to test querying.

  • Start a PostgreSQL server with the mysql_fdw extension installed.

  • Run SQL on PostgreSQL to set up:

    CREATE DATABASE vitess;
    \c vitess
    CREATE EXTENSION mysql_fdw;
    CREATE SERVER vitess FOREIGN DATA WRAPPER mysql_fdw OPTIONS (
        host 'vtgate',
        port '3306',
        sql_mode 'STRICT_TRANS_TABLES',
        use_remote_estimate 'true'
    );
    CREATE USER MAPPING FOR postgres SERVER vitess OPTIONS (
        username 'root',
        password 'qwerty123'
    );
    IMPORT FOREIGN SCHEMA postgres_fdw FROM SERVER vitess INTO public;
  • Do some test queries? For example:

    • A simple unsharded select
    • A big shared select
    • A select with pushdown from PostgreSQL to Vitess (a where clause, a join)

Also note that while compatibility with PostgreSQL FDW happens to be my use case, there is nothing specific to PostgreSQL in the changes made in this PR. It implements support for cursors in the MySQL protocol, and thus should be useful to anyone that wants to use cursors for any reason.

Presumably there could also be E2E tests that simply use a cursor from a regular MySQL client. I think having a specific E2E test for PostgreSQL FDW, while definitely a nice to have, doesn't have to be a specific blocker for this PR.

@harshit-gangal
Copy link
Member

harshit-gangal commented Oct 1, 2025

simply use a cursor from a regular MySQL client

This is exactly what I am looking for in our e2e test. we do not want postgres running in our CI

@systay systay modified the milestones: v23.0.0, v24.0.0 Oct 8, 2025
@github-actions
Copy link
Contributor

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Nov 10, 2025
@github-actions github-actions bot removed the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Nov 14, 2025
@github-actions
Copy link
Contributor

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Dec 14, 2025
DvdGiessen and others added 2 commits December 19, 2025 13:24
To be able to use the MySQL foreign data wrapper for Postgres, we have to
support server side cursors. To that end each connection now keeps track
of a list of open cursors, and implements the COM_STMT_FETCH command for
retrieving data from an open cursor.

Based on the implementation in the Dolthub fork of Vitess:
dolthub#228
dolthub#232

Co-Authored-By: James Cor <[email protected]>
Co-Authored-By: Aaron Son <[email protected]>
Signed-off-by: Daniël van de Giessen <[email protected]>
The previous commit which implemented support for server side cursors
also updated the function signature of the MySQL query functions to
return a integer "status" value instead of a boolean "more" value. One
of the flags in that status integer represents the "more" flag. This
commit updates all places where the MySQL query functions are called to
use this new status integer.

Signed-off-by: Daniël van de Giessen <[email protected]>
@github-actions github-actions bot removed the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Dec 20, 2025
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