You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[#28944] YSQL: Set the default value of auto analyze flag based on user set cbo flags
Summary:
Users currently have to manage cbo and auto analyze flags separately and can get into bad combinations. We do not want to enable auto analyze when cbo is in legacy mode (or anything other than on) because ANALYZE can update the `reltuples` field in pg_class for relations and cause unpredictable behavior. We intend to have the ysql_yb_enable_cbo flag default to false in code and be explicitly enabled by YBA/yugabyted for new clusters in 2025.2.
This diff (intended for backport to 2025.2) changes the auto analyze flag defaults to match this situation.
1.0 If the user explicits sets ysql_enable_auto_analyze, that setting is always used directly.
2.0 The default value of the flag ysql_enable_auto_analyze in the code is `false`, however it can be automatically turned on to true in the following cases:
2.1 ysql_yb_enable_cbo PG runtime gflag is set to `on` (currently this flag defaults to `legacy_mode` in code)
2.2 ysql_pg_conf_csv contains `yb_enable_cbo=on` (currently this GUC defaults to `legacy_mode` in code)
2.3 (logic prior to this change): both the deprecated auto analyze flags are set explictly by the user `--ysql_enable_auto_analyze_service=true` && `--ysql_enable_table_mutation_counter=true`
In all other cases, the default value of the flag (false) is used unchanged. For special cases, including precedence order when both ysql_yb_enable_cbo and ysql_pg_conf_csv are set, see Notes below.
Notes
1. When we change the default GUC yb_enable_cbo or PG flag ysql_yb_enable_cbo to "on" in code in the future, we will also need to update ysql_enable_auto_analyze default in the code to true and possibly invert this logic if we want to disable it for older clusters with cbo in legacy mode. Added a DCHECK to catch this case.
2. `yb_enable_cbo` can be configured on a per-db/role basis as any other GUC. However, that case isn't handled here. The user can set the GUC `yb_disable_auto_analyze` to match this GUC on the corresponding db/roles manually in such cases.
3. GUCs are case insensitive both in name and value.
4. Precedence order and repeated values
4.1 If ysql_yb_enable_cbo is set explicitly, its value is the one that is used in postgres config, so that is the value used to determine the auto analyze setting (set to true if cbo is on/true/yes/1, false otherwise). In this case, any setting for yb_enable_cbo in pg_conf_csv is not considered.
4.2 Repeated values for ysql_yb_enable_cbo like `ysql_yb_enable_cbo=on,ysql_yb_enable_cbo=off` are parsed by the gflags library to prefer the last setting.
4.3 ysql_pg_conf_csv can technically include multiple settings for `ysql_yb_enable_cbo` like `ysql_pg_conf_csv={yb_enaBle_cbo=off,yb_enAble_cbo=oN}`. In this case, the last value wins.
Jira: DB-18673
Test Plan:
Jenkins
```
./yb_build.sh --java-test TestPgRegressThirdPartyExtensionsHypopg
```
Backport-through: 2025.2
Tested the following combinations manually using yugabyted.
| **tserver flags** | **ysql_enable_auto_analyze** | **show yb_enable_cbo** |
| --tserver_flags not set | false (default) | legacy_mode |
| --tserver_flags=ysql_yb_enable_cbo=on | true | on |
| --tserver_flags=ysql_yb_enable_cbo=legacy_mode/off | false (default) | legacy_mode/off |
| --tserver_flags="ysql_pg_conf_csv={yb_enable_cbo=on/yes/true/1}" | true | on |
| --tserver_flags="ysql_pg_conf_csv={yb_enaBle_cbo=off,yb_enAble_cbo=oN}" | true | on |
| --tserver_flags="ysql_pg_conf_csv={yb_enable_cbo=legacy_mode}" | false (default) | legacy_mode |
| --tserver_flags="ysql_yb_enable_cbo=on,ysql_pg_conf_csv={yb_enable_cbo=off}" | true | on |
| --tserver_flags="ysql_yb_enable_cbo=off,ysql_pg_conf_csv={yb_enable_cbo=on}" | false (default) | off |
| --tserver_flags='"ysql_yb_enable_cbo=on,ysql_yb_enable_cbo=legacy_bnl_mode,ysql_pg_conf_csv={yb_enable_cbo=off,yb_enable_cbo=on}" | false (default) | legacy_bnl_mode
Test script
```
rm /tmp/out; cat /tmp/examples | while read flags; do echo $flags >> /tmp/out; bin/yugabyted stop && sleep 1 && bin/yugabyted start --listen 127.0.0.3 --tserver_flags="$flags" && grep 'server_main_util.*enable_auto_analyze' ~/var/logs/tserver/yb-tserver.INFO | tee -a /tmp/out && sleep 15 && bin/ysqlsh -h 127.0.0.3 -c "show yb_enable_cbo" | tee -a /tmp/out ; echo "---" >> /tmp/out; done
```
```
$ cat /tmp/examples
ysql_yb_enable_cbo=on
ysql_yb_enable_cbo=legacy_mode
ysql_pg_conf_csv={yb_enable_cbo=TRue}
ysql_pg_conf_csv={yb_enable_cbo=on}
ysql_pg_conf_csv={yb_enaBle_cbo=off,yb_enAble_cbo=oN}
ysql_pg_conf_csv={yb_enable_cbo=legacy_mode}
ysql_yb_enable_cbo=on,ysql_pg_conf_csv={yb_enable_cbo=off}
ysql_yb_enable_cbo=off,ysql_pg_conf_csv={yb_enable_cbo=on}
ysql_yb_enable_cbo=on,ysql_yb_enable_cbo=legacy_bnl_mode,ysql_pg_conf_csv={yb_enable_cbo=off,yb_enable_cbo=on}
```
Close: #28944
Reviewers: yguan, mtakahara, gkukreja, sanketh
Reviewed By: yguan, mtakahara
Subscribers: jason, hsunder, yql, ybase
Differential Revision: https://phorge.dev.yugabyte.com/D47676
0 commit comments