Repository navigation
Description
Context
PR #26881 fixes the default correctness bug from #26862: an index declared INVISIBLE is kept physically maintained and continues enforcing UNIQUE constraints, but it is excluded from normal optimizer candidates.
The follow-up gap is that MatrixOne already exposes optimizer_switch with use_invisible_indexes=off, but the planner does not consume that policy. The current eligibility helper therefore hard-codes:
optimizerEligible = visible
This implements the default mode, but there is no supported way to opt into invisible indexes for controlled plan comparison or troubleshooting.
Desired contract
Keep the current default behavior:
visible index -> eligible by default
invisible index -> excluded by default
invisible UNIQUE -> still maintained and still enforces uniqueness
Add an explicit session or statement policy equivalent to MySQL use_invisible_indexes=on:
optimizerEligible = visible || allowInvisible
When enabled, invisible indexes should participate in ordinary cost-based selection. They should not be forced merely because they are eligible.
Scope
- Parse and consume use_invisible_indexes from optimizer_switch at the planner boundary.
- If supported by the existing hint framework, support a statement-scoped SET_VAR override.
- Keep catalog metadata responsible only for persisted visibility; keep optimizer eligibility in planner/session policy.
- Apply the policy consistently to regular, master, spatial, fulltext, vector, join, ORDER BY/GROUP BY, and index-hint paths.
- Define the behavior of USE/FORCE INDEX for invisible indexes in each policy mode and match the chosen compatibility contract.
- Include the policy in plan-cache validity or keying so changing the session setting cannot reuse a plan built under the opposite policy.
- Preserve index maintenance, unique enforcement, publication, SHOW CREATE, and visibility persistence semantics from PR fix(plan): honor invisible indexes in optimizer #26881.
Acceptance tests
- Default off: invisible index is absent from EXPLAIN candidate selection.
- Session on: the same query may choose the invisible index when cost-based planning selects it.
- Statement override, if enabled: only that statement sees invisible indexes.
- USE/FORCE/IGNORE INDEX behavior is deterministic and documented for both modes.
- Regular, unique, fulltext, spatial, vector, join, and ORDER BY/GROUP BY paths have at least one black-box or typed planner control.
- Toggling the policy cannot reuse an incompatible cached plan.
- INSERT/UPDATE duplicate-key behavior is unchanged for invisible UNIQUE indexes.
Related: #26881
Fixes the remaining compatibility gap after #26881.
Activity