Skip to content

Session.GetSessionSysVar returns nil for registered sysvars missing from the per-session map - #24530

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
cpegeric:fix_session_sysvar_default
May 21, 2026
Merged

Session.GetSessionSysVar returns nil for registered sysvars missing from the per-session map#24530
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
cpegeric:fix_session_sysvar_default

Conversation

@cpegeric

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24529

What this PR does / why we need it:

  1. Fix SystemVariables.Get to fall back internally. Broader scope (SystemVariables would need to know about gSysVarsDefs), but covers any direct caller of
    Get too.
  2. Pre-populate sesSysVars at session creation by merging gSysVarsDefs defaults into the cloned account snapshot. Most principled — the per-session map
    becomes complete — but more invasive at session-init time.

Going with the localized fix in GetSessionSysVar as the lowest-risk first step; options 1/2 can follow if the same nil-on-miss pattern bites other call
sites.

Tests

TestGetSessionSysVar_MapMissFallsBackToDefault (pkg/frontend/authenticate_test.go) asserts the new fallback for ivf_threads_build (int64) and
kmeans_train_percent (float64).

… map miss

Session.GetSessionSysVar previously returned interface{}(nil) when
ses.sesSysVars.Get(name) saw a map miss for a registered sysvar.
sesSysVars is a clone of the per-account snapshot from
mo_mysql_compatibility_mode; sysvars added to gSysVarsDefs without a
corresponding catalog row are absent from the cloned map, and Get
returns interface{}(nil) on map miss instead of the registered
Default. That violates MySQL `SELECT @@name` semantics (session value
> global default, never nil for a registered name) and breaks
downstream consumers like sub-Compiles spawned by CREATE TABLE CLONE
that try to read vector-index sysvars (ivf_threads_build,
kmeans_train_percent, ...) — they receive nil and either fail or
silently use zero values.

The function already had a wholesale-nil fallback (`if ses.sesSysVars
== nil { return gSysVarsDefs[name].Default }`); this commit extends it
to cover the per-key map-miss case, the realistic scenario for any
sysvar registered after the per-account snapshot was taken.

New TestGetSessionSysVar_MapMissFallsBackToDefault asserts both
`ivf_threads_build` (int64 default 0) and `kmeans_train_percent`
(float64 default 10) resolve correctly when the per-session map is
empty.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cpegeric
cpegeric requested a review from XuPeng-SH as a code owner May 21, 2026 10:45
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the Session.GetSessionSysVar fallback change and the added regression test. The change is small, localized, consistent with the existing nil-session fallback behavior, and the focused frontend sysvar tests passed locally.

@mergify

mergify Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-05-21 18:08 UTC · Rule: main
  • Checks passed · in-place
  • Merged2026-05-21 19:12 UTC · at 6051479a85fcbf34d14374a4800d283e0913ab59 · squash

This pull request spent 1 hour 3 minutes 53 seconds in the queue, including 1 hour 3 minutes 18 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 8fab3f2 into matrixorigin:main May 21, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 21, 2026
ULookup pushed a commit to ULookup/matrixone that referenced this pull request May 26, 2026
…rom the per-session map (matrixorigin#24530)

1. Fix SystemVariables.Get to fall back internally. Broader scope (SystemVariables would need to know about gSysVarsDefs), but covers any direct caller of
Get too.
2. Pre-populate sesSysVars at session creation by merging gSysVarsDefs defaults into the cloned account snapshot. Most principled — the per-session map
becomes complete — but more invasive at session-init time.

Going with the localized fix in GetSessionSysVar as the lowest-risk first step; options 1/2 can follow if the same nil-on-miss pattern bites other call
sites.

Tests

TestGetSessionSysVar_MapMissFallsBackToDefault (pkg/frontend/authenticate_test.go) asserts the new fallback for ivf_threads_build (int64) and
kmeans_train_percent (float64).

Approved by: @XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants