Files
documentdb/pg_documentdb/sql/udfs/index_mgmt/create_index_background--latest.sql
T
Amit Prabhudesai 84ba0c99d8 Merged PR 1572685: [OSS] Fix background index builds for documentdb
### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes

### Are you introducing any new config? If yes, do you have tests with and without them being set?
No

### ChangeLog (Refer [Template](../oss/CHANGELOG.md))

### Description
Get background index builds to work for single-node documentdb.

This changeset fixes background index builds for OSS by:

1. Scheduling the background index build tasks
2. Moving the distributed functionality (which had not being refactored out of the indexing code during the move to OSS) into distributed hooks, with the base implementation for single-node.
3. Refactoring SQL tests to get even with the above changes.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for background index builds in DocumentDB.

#### PR Summary
This pull request addresses issues with background index builds in DocumentDB by adding comprehensive tests and handling various edge cases.
- `commands_create_indexes_background.out`: Added extensive test cases to validate the behavior of `create_indexes_background` function, including handling of invalid inputs, unique constraints, and various index specifications.
- Introduced a new schema and function to manage index job statuses.
- Enhanced error handling and validation for index creation requests, ensuring proper error messages and statuses are returned for invalid operations.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
2025-05-09 14:08:53 +08:00

60 lines
2.7 KiB
SQL

CREATE OR REPLACE PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(IN p_job_index int)
LANGUAGE C
AS 'MODULE_PATHNAME', $procedure$command_build_index_concurrently$procedure$;
COMMENT ON PROCEDURE __API_SCHEMA_INTERNAL__.build_index_concurrently(int)
IS 'Builds a index for a collection';
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status(
IN p_arg __CORE_SCHEMA__.bson,
OUT retval __CORE_SCHEMA__.bson,
OUT ok boolean,
OUT complete boolean)
RETURNS record
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME', $$command_check_build_index_status$$;
COMMENT ON FUNCTION __API_SCHEMA_INTERNAL_V2__.check_build_index_status(__CORE_SCHEMA__.bson)
IS 'Calls check_build_index_status_internal.';
-- TODO: DROP the __API_SCHEMA__.create_indexes_background
CREATE OR REPLACE FUNCTION __API_SCHEMA_V2__.create_indexes_background(
p_database_name text,
p_index_spec __CORE_SCHEMA__.bson,
OUT retval __CORE_SCHEMA__.bson,
OUT ok boolean,
OUT requests __CORE_SCHEMA__.bson)
RETURNS record
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME', $$command_create_indexes_background$$;
COMMENT ON FUNCTION __API_SCHEMA_V2__.create_indexes_background(text, __CORE_SCHEMA__.bson)
IS 'Submits the build index(es) requests on a collection and waits for them to finish.';
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal(
IN p_arg __CORE_SCHEMA__.bson)
RETURNS __CORE_SCHEMA__.bson
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME', $$command_check_build_index_status_internal$$;
COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.check_build_index_status_internal(__CORE_SCHEMA__.bson)
IS 'Checks for build index(es) requests to finish.';
DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.create_indexes_background_internal CASCADE;
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal(
IN p_database_name text,
IN p_arg __CORE_SCHEMA__.bson)
RETURNS __CORE_SCHEMA__.bson
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME', $$command_create_indexes_background_internal$$;
COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.create_indexes_background_internal(text,__CORE_SCHEMA__.bson)
IS 'Queues the Index creation request(s) on a collection';
DROP FUNCTION IF EXISTS __API_SCHEMA_INTERNAL__.schedule_background_index_build_workers;
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(IN p_force_override boolean DEFAULT false)
RETURNS void
LANGUAGE C
AS 'MODULE_PATHNAME', $$schedule_background_index_build_jobs$$;
COMMENT ON FUNCTION __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs(boolean)
IS 'Schedules the background index build cron job.';