WL#17265: Enable hypergraph optimizer in community builds
Today, community builds of MySQL do not include support for enabling the hypergraph optimizer, even though the server already exposes the hypergraph_optimizer flag in optimizer_switch. As a result, attempts to enable it (for example via SET optimizer_switch, SET GLOBAL, SET PERSIST, --optimizer-switch, or SET_VAR hints) either fail or are ignored, depending on the mechanism used.
This worklog changes the community build configuration so that the hypergraph optimizer is compiled in by default and made available for use in community releases, unless it is explicitly configured out at build time. The default runtime behavior remains unchanged: the hypergraph optimizer is not enabled by default in sessions.
When the feature is included in the build, users can opt in at runtime by enabling hypergraph_optimizer=on through the existing optimizer_switch mechanisms (session, global, persisted, startup option, or per-statement hinting). When the feature is not included (for example, when WITH_HYPERGRAPH_OPTIMIZER=OFF), attempts to enable it should continue to be rejected or ignored in the same way as before.
Functional Requirements (FR)
FR1 — Default build behavior (availability vs. default use)
- When MySQL is configured with CMake without specifying
WITH_HYPERGRAPH_OPTIMIZER(or specifying it asON), the hypergraph optimizer is built and available, but is not enabled by default in sessions (i.e., remains controlled byoptimizer_switchdefaults).
FR2 — Session-level SET optimizer_switch succeeds when available
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=ON(explicitly or by default per FR1):SET optimizer_switch='hypergraph_optimizer=on';shall succeed (no error).- The change shall be observable via
SELECT @@optimizer_switch;.
FR3 — Server startup option --optimizer-switch enables it when available
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=ON(explicitly or by default per FR1):- Starting
mysqldwith--optimizer-switch=hypergraph_optimizer=onshall succeed. - In a fresh client session, the state shall be observable via:
SELECT @@optimizer_switch;SELECT @@global.optimizer_switch;- Both shall reflect
hypergraph_optimizer=on(subject to usualoptimizer_switchsemantics).
- Starting
FR4 — Global SET GLOBAL optimizer_switch succeeds when available
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=ON(explicitly or by default per FR1):SET GLOBAL optimizer_switch='hypergraph_optimizer=on';shall succeed (no error).- The change shall be observable via
SELECT @@global.optimizer_switch;in the same session. - In a newly created session after the global change, the effective session value shall be observable via
SELECT @@session.optimizer_switch;and reflecthypergraph_optimizer=on(subject to usualoptimizer_switchsemantics).
FR5 — SET PERSIST optimizer_switch succeeds and persists when available
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=ON(explicitly or by default per FR1):SET PERSIST optimizer_switch='hypergraph_optimizer=on';shall succeed (no error).- In the same session,
SELECT @@session.optimizer_switch;shall not change solely due toSET PERSIST. - In the same session,
SELECT @@global.optimizer_switch;shall reflecthypergraph_optimizer=onafter theSET PERSIST. - In a newly created session after the
SET PERSIST,SELECT @@session.optimizer_switch;shall reflecthypergraph_optimizer=on(subject to usualoptimizer_switchsemantics). - After a server restart,
SELECT @@global.optimizer_switch;shall reflecthypergraph_optimizer=on, and a newly created session shall reflecthypergraph_optimizer=oninSELECT @@session.optimizer_switch;(subject to usualoptimizer_switchsemantics).
FR6 — SET_VAR hint can enable and causes hypergraph optimization when available
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=ON(explicitly or by default per FR1):- A query using
/*+ SET_VAR(optimizer_switch='hypergraph_optimizer=on') */shall succeed (no error). - The hypergraph optimizer shall be used for optimizing that statement.
- Usage shall be observable using optimizer trace (or equivalent tracing mechanism used by MySQL).
- A query using
FR7 — ENABLE_HYPERGRAPH_OPTIMIZER forces inclusion
- If
ENABLE_HYPERGRAPH_OPTIMIZER=ONis specified:- The resulting configuration shall set
WITH_HYPERGRAPH_OPTIMIZER=ON, - even if
WITH_HYPERGRAPH_OPTIMIZER=OFFis explicitly provided in the same CMake invocation.
- The resulting configuration shall set
FR8 — Session-level SET optimizer_switch fails when not built
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=OFF:SET optimizer_switch='hypergraph_optimizer=on';shall fail with errorER_HYPERGRAPH_NOT_SUPPORTED_YET(3999).- The error message shall indicate lack of support due to
WITH_HYPERGRAPH_OPTIMIZER=OFF(e.g., “to enable it, build with CMake option WITH_HYPERGRAPH_OPTIMIZER=ON”).
FR9 — Server startup option --optimizer-switch is accepted but not applied when not built
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=OFF:- Starting
mysqldwith--optimizer-switch=hypergraph_optimizer=onshall succeed (server starts). - In a fresh session, both:
SELECT @@optimizer_switch;SELECT @@global.optimizer_switch;shall showhypergraph_optimizer=off.- Attempting
SET optimizer_switch='hypergraph_optimizer=on';after startup shall fail as specified in FR8.
- Starting
FR10 — Global SET GLOBAL optimizer_switch fails when not built
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=OFF:SET GLOBAL optimizer_switch='hypergraph_optimizer=on';shall fail with errorER_HYPERGRAPH_NOT_SUPPORTED_YET(3999).- The error message shall indicate lack of support due to
WITH_HYPERGRAPH_OPTIMIZER=OFF(e.g., “to enable it, build with CMake option WITH_HYPERGRAPH_OPTIMIZER=ON”). SELECT @@global.optimizer_switch;in the same session shall not showhypergraph_optimizer=on.- In a newly created session after the failed global attempt,
SELECT @@session.optimizer_switch;shall not showhypergraph_optimizer=on.
FR11 — SET PERSIST optimizer_switch fails when not built
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=OFF:SET PERSIST optimizer_switch='hypergraph_optimizer=on';shall fail with errorER_HYPERGRAPH_NOT_SUPPORTED_YET(3999).- The error message shall indicate lack of support due to
WITH_HYPERGRAPH_OPTIMIZER=OFF(e.g., “to enable it, build with CMake option WITH_HYPERGRAPH_OPTIMIZER=ON”). SELECT @@global.optimizer_switch;in the same session shall not showhypergraph_optimizer=on.- In a newly created session after the failed attempt,
SELECT @@session.optimizer_switch;shall not showhypergraph_optimizer=on. - After a server restart,
SELECT @@global.optimizer_switch;and a newly created session’sSELECT @@session.optimizer_switch;shall not showhypergraph_optimizer=on.
FR12 — SET_VAR hint is tolerated but does not enable it when not built
- In builds where
WITH_HYPERGRAPH_OPTIMIZER=OFF:- A statement using
/*+ SET_VAR(optimizer_switch='hypergraph_optimizer=on') */shall execute successfully. - The hypergraph optimizer shall not be used for that statement.
- The server shall emit warning
ER_HYPERGRAPH_NOT_SUPPORTED_YET(3999) for the statement, and the warning text shall indicateWITH_HYPERGRAPH_OPTIMIZER=OFF.
- A statement using
Non-Functional Requirements (NFR)
NFR1 — Default runtime behavior unchanged
- When
WITH_HYPERGRAPH_OPTIMIZER=ONbutENABLE_HYPERGRAPH_OPTIMIZER=OFF(default), server behavior and query planning shall remain unchanged unless a user explicitly enableshypergraph_optimizer=onviaoptimizer_switch.
NFR2 — No performance regressions in default configuration
- In the default runtime configuration (
hypergraph_optimizer=off), there shall be no measurable performance regressions attributable to this WL (planning latency and execution time unchanged within normal noise).
NFR3 — No new external dependencies
- Compiling in the hypergraph optimizer by default shall not introduce new external build/runtime dependencies for community builds beyond those already required for the server.
NFR4 — Resource footprint remains acceptable
- The incremental impact on build artifacts (binary size) and memory usage in the default runtime configuration shall remain within acceptable limits for community builds.
NFR5 — Backward compatible interfaces
- No new SQL syntax or new system variables are introduced; existing
optimizer_switchsemantics and supported scopes (SET,SET GLOBAL,SET PERSIST,--optimizer-switch,SET_VAR) remain backward compatible.
NFR6 — Diagnostics quality
- When hypergraph optimization cannot be enabled because it is compiled out (
WITH_HYPERGRAPH_OPTIMIZER=OFF), the resulting error/warning shall clearly identify the build-time reason so users can self-diagnose misconfiguration.
Observability / Verification Notes
Switch observability:
- Use
SELECT @@optimizer_switch;to confirm the effective session value. - Use
SELECT @@global.optimizer_switch;to confirm the global value. - For these requirements, it is sufficient to verify that the returned string contains
hypergraph_optimizer=onorhypergraph_optimizer=offas applicable.
- Use
Startup option verification:
- When verifying
mysqld --optimizer-switch=..., use a fresh connection (new session) after startup. - The requirements intentionally distinguish between:
- “server starts successfully” (option accepted at startup), and
- “setting takes effect” (visible in
@@optimizer_switch/@@global.optimizer_switch).
- When verifying
Optimizer usage verification (hypergraph vs. non-hypergraph):
- When the requirements say “hypergraph optimizer shall be used,” it should be verified via optimizer trace (or an equivalent supported trace facility).
- The recommended, concrete marker is presence/absence of the string
Constructed hypergraphin the optimizer trace output. - When hypergraph optimization is required (e.g., FR4 with
WITH_HYPERGRAPH_OPTIMIZER=ON), the optimizer trace shall containConstructed hypergraph. - When hypergraph optimization is not expected (e.g., FR8 with
WITH_HYPERGRAPH_OPTIMIZER=OFF), the optimizer trace shall not containConstructed hypergraph. - The trace may be queried using the usual optimizer-trace tables/views used by the test suite (for example, selecting
TRACEand filtering withLIKE '%Constructed hypergraph%').
Error and warning verification:
- For
SET optimizer_switch='hypergraph_optimizer=on'withWITH_HYPERGRAPH_OPTIMIZER=OFF, verify: - the statement fails with error code 3999 (
ER_HYPERGRAPH_NOT_SUPPORTED_YET), and - the message indicates
WITH_HYPERGRAPH_OPTIMIZER=OFF. - For
SET_VAR(optimizer_switch='hypergraph_optimizer=on')withWITH_HYPERGRAPH_OPTIMIZER=OFF, verify: - the statement executes,
SHOW WARNINGS;returns warning code 3999, and- the warning message indicates
WITH_HYPERGRAPH_OPTIMIZER=OFF.
- For
Example SQL (optimizer trace marker)
The following sequence illustrates one way to capture and assert the trace marker:
-- Enable optimizer trace collection (scope and options may vary).
SET optimizer_trace = 'enabled=on';
SET optimizer_trace_max_mem_size = 1048576;
-- Run the statement under test.
SELECT /*+ SET_VAR(optimizer_switch='hypergraph_optimizer=on') */ *
FROM t;
-- Verify marker presence/absence.
SELECT TRACE
FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE
WHERE TRACE LIKE '%Constructed hypergraph%';
Build configuration interface
Introduce/clarify two separate build-time controls:
WITH_HYPERGRAPH_OPTIMIZER(defaultON): controls whether the hypergraph optimizer is compiled in and therefore may be enabled at runtime.ENABLE_HYPERGRAPH_OPTIMIZER(defaultOFF): controls whether the hypergraph optimizer is enabled by default inOPTIMIZER_SWITCH_DEFAULT.
Precedence/consistency rule:
- If
ENABLE_HYPERGRAPH_OPTIMIZER=ONis specified, thenWITH_HYPERGRAPH_OPTIMIZERshall be treated asON(ie, enabling by default implies the code must be built).
- If
Runtime interface
- No new SQL syntax is introduced.
- The runtime mechanism for enabling/disabling hypergraph optimization remains the existing
optimizer_switchsystem variable, via:- session scope:
SET optimizer_switch='hypergraph_optimizer=on|off' - global scope:
SET GLOBAL optimizer_switch='hypergraph_optimizer=on|off' - persisted scope:
SET PERSIST optimizer_switch='hypergraph_optimizer=on|off' - server startup:
mysqld --optimizer-switch=... - per-statement hint:
/*+ SET_VAR(optimizer_switch='hypergraph_optimizer=on|off') */
- session scope:
Error/warning surface
When
WITH_HYPERGRAPH_OPTIMIZER=OFF, the server shall continue to reject attempts to enable the hypergraph optimizer usingSET optimizer_switch/SET GLOBAL/SET PERSISTwith errorER_HYPERGRAPH_NOT_SUPPORTED_YET(3999), and shall continue to ignoreSET_VARenabling attempts while raising warningER_HYPERGRAPH_NOT_SUPPORTED_YET(3999).The error/warning text shall indicate the build-time reason (eg,
to enable it, build with CMake option WITH_HYPERGRAPH_OPTIMIZER=ON).
Observability interface
The effective configuration is observable via the existing system variable interfaces:
SELECT @@session.optimizer_switch;SELECT @@global.optimizer_switch;
When hypergraph optimization is used for a statement, this is observable via optimizer trace output (eg, by the presence of
Constructed hypergraphinINFORMATION_SCHEMA.OPTIMIZER_TRACE.TRACE).
Overview
WL#17265 is implemented purely as a build-configuration change plus a small adjustment to the user-facing error text. No new runtime knobs are introduced; instead, the existing optimizer_switch entry hypergraph_optimizer becomes usable in community builds by compiling in the hypergraph optimizer code by default.
CMake changes
1) Default compilation of hypergraph optimizer
- Set
WITH_HYPERGRAPH_OPTIMIZERto be a normal CMake option with defaultON. - Remove/avoid build-type dependent defaults (eg, “ON only for Debug builds”).
- Rationale: community builds should include the code unless explicitly configured out.
2) Separate “compiled in” vs “enabled by default”
- Keep
ENABLE_HYPERGRAPH_OPTIMIZERas the build-time switch that controls whetherhypergraph_optimizer=onis present inOPTIMIZER_SWITCH_DEFAULT. - Maintain the invariant:
- if
ENABLE_HYPERGRAPH_OPTIMIZER=ONthenWITH_HYPERGRAPH_OPTIMIZERmust evaluate toON. - This prevents a contradictory configuration where the default attempts to enable a feature that was compiled out.
- if
3) Internal option overrides
- Preserve existing internal override logic (eg, if an internal feature set such as
WITH_RAPIDrequires it) by defining the option early ininternal/cmake/mysql_internal_options.cmake, so later defaults do not override it.
Server behavior (unchanged, except where noted)
1) Default runtime behavior
- Even when the hypergraph optimizer is compiled in, it remains disabled by default at runtime.
- Users opt in by setting
optimizer_switch(session/global/persist), passing--optimizer-switch, or usingSET_VARhints.
2) Behavior when compiled out
- If
WITH_HYPERGRAPH_OPTIMIZER=OFF, attempts to enable the hypergraph optimizer are rejected/ignored as before:SET optimizer_switch='hypergraph_optimizer=on'fails with error 3999.SET GLOBAL .../SET PERSIST ...fails with error 3999.--optimizer-switch=hypergraph_optimizer=onis accepted for startup but does not result inhypergraph_optimizer=onat runtime.SET_VAR(optimizer_switch='hypergraph_optimizer=on')is tolerated but does not enable hypergraph optimization and raises warning 3999.
3) Error message wording (change)
- Update the message for
ER_HYPERGRAPH_NOT_SUPPORTED_YET(3999) emitted by the optimizer-switch validation logic to reference the explicit build-time reason:ERROR 42000: The hypergraph optimizer does not yet support 'this build configuration; to enable it, build with CMake option WITH_HYPERGRAPH_OPTIMIZER=ON'
- Rationale: after this WL, “non-debug builds” is no longer the defining condition; the controlling factor is the compile-time option.
Validation/observability
Confirm compiled-in behavior by enabling
hypergraph_optimizer=onand verifying:@@optimizer_switch/@@global.optimizer_switchchanges as expected for the chosen scope.- optimizer trace contains the marker
Constructed hypergraphfor statements optimized using hypergraph.
Confirm compiled-out behavior by verifying error/warning code 3999 and that optimizer trace does not contain
Constructed hypergraphwhen attempting to enable viaSET_VAR.