-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: don't apply disallow_full_table_scans to internal executors
We have various checks for disallow_full_table_scans: 1. in connExecutor we fail the statement with an error if it uses a full scan 2. in execbuild we fail the statement with an error if there is an index hint that causes a full scan 3. in the coster we add hugeCost to full scans, to try and avoid them We don't want disallow_full_table_scans to apply to anything done by internal executors. (1) was already checking whether this connExecutor was internal. (2) and (3) were not, which led to #137404. #137681 fixed this by setting disallow_full_table_scans in `NewInternalSessionData`, but we only use `NewInternalSessionData` for some uses of the internal executor. This commit explicitly checks `SessionData().Internal` in (2) and (3) to match (1), so that we don't get any of the disallow_full_table_scans behavior for any use of the internal executor, including populating virtual tables. This commit also adds `SessionData().Internal` to the memo staleness check. This behavior can be observed with the following diff, which adds an index hint to the `crdb_internal.system_jobs` virtual table SQL: ``` diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index 80a5342b56a..99ccb8f1611 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -975,7 +975,7 @@ SELECT DISTINCT(id), status, created, payload.value AS payload, progress.value AS progress, created_by_type, created_by_id, claim_session_id, claim_instance_id, num_runs, last_run, job_type FROM -system.jobs AS j +system.jobs@jobs_status_created_idx AS j LEFT JOIN system.job_info AS progress ON j.id = progress.job_id AND progress.info_key = 'legacy_progress' INNER JOIN system.job_info AS payload ON j.id = payload.job_id AND payload.info_key = 'legacy_payload' ` ``` With this diff, the following SQL hits (2) and fails with an error, even though it uses the internal executor and thus should not error: ``` SET disallow_full_table_scans = on; SELECT * FROM crdb_internal.jobs; ``` With this commit we no longer fail, matching the behavior without the index hint. Informs: #137404 Informs: #123783 Release note: None
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters