GPT Integration for SQL Stored Procedure Optimization in CI/CD Pipeline

agoda · E-commerce · 2024 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: database performance optimization in CI/CD

Agoda needed to reduce the manual database-developer effort required to analyze failed stored-procedure performance tests, improve SQL quality, and speed merge-request approvals without letting GPT make unreviewed logic changes.

Constraints:

Architecture

Agoda integrated GPT into its stored-procedure CI/CD workflow. Each new SP merge request runs performance tests; if optimization help is needed, the system prepares SP code, table structures, indexes, and the performance test report as context for GPT. GPT analyzes bottlenecks, rewrites queries, and suggests indexes. The CI/CD workflow posts a GitLab MR summary with original-vs-optimized performance comparison and a click-to-apply option, while developers and dbdevs review GPT's optimized SP and index suggestions before applying changes.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  developer["Developer"] --> gitlab_merge_request["GitLab merge request"]
  gitlab_merge_request --> ci_cd_performance_tests["CI/CD performance tests"]
  ci_cd_performance_tests --> context_preparation["Context preparation"]
  context_preparation --> gpt_optimizer["GPT optimizer"]
  gpt_optimizer --> optimized_sp_and_index_suggestions["Optimized SP and index suggestions"]
  optimized_sp_and_index_suggestions --> mr_optimization_comment["MR optimization comment"]
  mr_optimization_comment --> gitlab_merge_request
  gitlab_merge_request --> developer
  gitlab_merge_request --> database_developer["Database developer"]
  logic_verification_framework["Logic verification framework"] --> gpt_optimizer
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Developer Creates stored procedure changes and reviews optimization recommendations in the merge request. GitLab merge request
GitLab merge request Review surface where performance results, GPT suggestions, and click-to-apply actions are shown. CI/CD performance tests, MR optimization comment, Developer, Database developer
CI/CD performance tests Pipeline step that measures stored-procedure performance and detects failures. Context preparation
Context preparation Collects SP code, table structures, indexes, and performance test reports for GPT. GPT optimizer
GPT optimizer Analyzes performance issues, rewrites stored procedures, and suggests indexes. Optimized SP and index suggestions
Optimized SP and index suggestions Structured GPT output containing revised SQL and index recommendations. MR optimization comment
MR optimization comment Merge-request summary with performance comparison and click-to-apply option. GitLab merge request
Database developer Dbdev reviewer who evaluates GPT suggestions and supports manual/automated optimization quality. GitLab merge request
Logic verification framework Planned framework to compare original and optimized SP outputs across test cases. GPT optimizer

Data flow

A developer opens a merge request for a stored procedure, triggering performance tests in CI/CD. The system packages SP code, table structures/indexes, and the performance report for GPT. GPT returns an optimized SP and suggested indexes, plus analysis of bottlenecks. The workflow adds a GitLab MR comment with a side-by-side performance comparison and a clickable option to apply GPT's commit, leaving developers and dbdevs to evaluate and act on the recommendation.

3 supporting quotes
“Every new SP triggers a merge request (MR), which kicks off performance tests in our CI/CD pipeline.”article, stated
“We provide GPT with comprehensive inputs to ensure accurate analysis:”article, stated
“The summary result includes a performance comparison between the original SP and the GPT-optimized version.”article, stated

Why this architecture

Agoda placed GPT directly at the point where SQL performance failures already surface: the CI/CD merge-request workflow. Supplying code, schema/indexes, and performance reports gives GPT actionable context, while side-by-side comparisons and click-to-apply review keep humans in control before optimized SQL or index changes enter the codebase.

3 supporting quotes
“we integrated it seamlessly into our CI/CD pipeline.”article, stated
“This side-by-side comparison helps dbdevs and developers make informed decisions by highlighting the differences in performance.”article, stated
“Below is an example of a GitLab MR comment where developers can review GPT’s suggestions and click to apply the optimized SP and suggested indexes:”article, stated

Models used: GPT

Scale

Alternatives considered (roads not taken)

Keep performance-test failure analysis fully manual

Rejected because: Manual analysis consumed hundreds of dbdev man-days and slowed merge-request approvals.

“If the test fails, it falls on our database developers (dbdevs) to manually analyze the procedure, identify bottlenecks, and suggest improvements.”article, stated
“Our goal was to reduce manual review time, speed up MR approvals, and give developers access to self-service tools for performance tuning.”article, stated

Ask GPT to optimize SQL from stored-procedure code alone

Rejected because: Agoda supplies schema, index, and performance-report context so GPT can identify bottlenecks and produce actionable recommendations.

3 supporting quotes
“SP Code: The SQL code of the stored procedure that needs optimization.”article, stated
“Table Structures and Indexes: Information about the database schema, including table definitions and existing indexes.”article, stated
“Performance Test Report: Results from the performance test, highlighting execution times, bottlenecks, or inefficiencies.”article, stated

Auto-apply GPT rewrites without review

Rejected because: The workflow presents performance comparison and click-to-apply controls so developers and dbdevs can decide the next step.

“users can easily evaluate the impact of GPT’s suggestions and decide on the next steps.”article, stated
“developers can review GPT’s suggestions and click to apply the optimized SP and suggested indexes”article, stated

Trust GPT rewrites without semantic equivalence checks

Rejected because: Some GPT rewrites change entire logic, so Agoda is building automated logic verification to compare original and optimized outputs.

“for more complex SPs, GPT sometimes revises the entire logic, resulting in significant code changes.”article, stated
“developing tools and frameworks to automatically compare the outputs of the original and optimized SPs across a range of test cases”article, stated

Patterns

tool-use-orchestration (CI/CD optimization workflow)

The workflow coordinates CI/CD tests, performance reports, schema/index context, GPT analysis, merge-request comments, and click-to-apply commits.

“To maximize the benefits of GPT in optimizing stored procedures (SPs), we integrated it seamlessly into our CI/CD pipeline.”article, stated
“Below is an example of a GitLab MR comment where developers can review GPT’s suggestions and click to apply”article, stated

structured-output-contract (SQL recommendation format)

GPT produces two actionable outputs for each stored procedure: an optimized SP and suggested indexes, with performance comparison shown in the MR.

3 supporting quotes
“GPT provides two key outputs for each SP:”article, stated
“Optimized SP: A revised version of the stored procedure with improvements to enhance performance.”article, stated
“Suggested Indexes: Recommendations for new or modified indexes to address inefficiencies.”article, stated

human-in-the-loop-gate (safe code change)

Developers and dbdevs review GPT's suggestions and performance comparisons in the MR before choosing whether to apply generated SQL/index changes.

“developers can review GPT’s suggestions and click to apply the optimized SP and suggested indexes”article, stated
“users can easily evaluate the impact of GPT’s suggestions and decide on the next steps.”article, stated

eval-driven-development (performance and equivalence checks)

Performance tests trigger the workflow, side-by-side comparisons validate the optimization effect, and Agoda is building logic verification tests to ensure behavior remains identical.

“Every new SP triggers a merge request (MR), which kicks off performance tests in our CI/CD pipeline.”article, stated
“developing tools and frameworks to automatically compare the outputs of the original and optimized SPs across a range of test cases”article, stated

observability-tracing (performance diagnostics)

The GPT prompt includes performance test reports that expose execution times, bottlenecks, high resource use, full scans, and inefficient joins to guide recommendations.

“GPT uses the performance test report to understand the current performance issues, such as slow execution times or high resource usage.”article, stated
“GPT identifies specific performance problems, such as full table scans, inefficient joins, or bottlenecks in query execution.”article, stated

Tradeoffs

Put GPT inside the merge-request workflow.

Chose CI/CD-integrated GPT recommendations and MR comments over Separate optimization tooling outside the developer workflow.

Rationale: Embedding suggestions in the MR makes performance context and click-to-apply changes available where developers and dbdevs already review SPs.

“This integration ensures that GPT’s suggestions are part of the development process”article, stated
“By adding this comparison to the MR as a summary, users can easily evaluate the impact of GPT’s suggestions”article, stated

Expose self-service optimization while keeping review.

Chose Click-to-apply GPT suggestions over Fully manual dbdev optimization or fully automatic code modification.

Rationale: The feature empowers developers and reduces dbdev workload without removing the review step needed for correctness.

“Empowered Developers: The self-service tuning tools and click-to-apply feature streamline the optimization process.”article, stated
“developers can review GPT’s suggestions and click to apply the optimized SP and suggested indexes”article, stated

Use performance comparison as the MR decision artifact.

Chose Side-by-side original-versus-optimized performance comparison over A raw GPT recommendation without measured impact.

Rationale: The comparison lets reviewers judge whether the generated SQL/index changes produce enough performance improvement to accept.

“The summary result includes a performance comparison between the original SP and the GPT-optimized version.”article, stated
“This side-by-side comparison helps dbdevs and developers make informed decisions by highlighting the differences in performance.”article, stated

Expand beyond MR-triggered optimization.

Chose A future assistant integrated directly with Agoda's database environment over Requiring developers to open a merge request before accessing GPT optimization.

Rationale: Direct database-environment access would make GPT optimization available earlier and more conveniently, but it is described as a future expansion.

“developing a new assistant that will integrate directly with Agoda’s database environment”article, stated
“allowing developers to access GPT’s capabilities without opening a merge request.”article, stated

Gotchas (what bit them)

Manual SQL optimization becomes a hidden approval bottleneck at scale.

Root cause: Each failed performance test forces dbdevs to inspect stored procedures, execution behavior, and bottlenecks manually.

Resolution: Feed performance-test context to GPT and surface recommendations directly in the MR to reduce manual review time.

“If the test fails, it falls on our database developers (dbdevs) to manually analyze the procedure, identify bottlenecks, and suggest improvements.”article, stated
“Reduced Manual Reviews: Developers and dbdevs spend less time analyzing performance issues and debugging SPs.”article, stated

GPT needs execution and schema context to produce useful SQL recommendations.

Root cause: Stored-procedure performance depends on table structures, indexes, execution times, bottlenecks, and resource usage, not just SQL text.

Resolution: Prepare SP code, table structures/indexes, and performance test reports as input context.

“We provide GPT with comprehensive inputs to ensure accurate analysis:”article, stated
“Results from the performance test, highlighting execution times, bottlenecks, or inefficiencies.”article, stated

An optimization can silently change stored-procedure logic.

Root cause: For complex stored procedures, GPT may rewrite the entire logic rather than making a local optimization.

Resolution: Develop automated logic verification to compare original and optimized outputs across test cases.

“for more complex SPs, GPT sometimes revises the entire logic, resulting in significant code changes.”article, stated
“ensuring the logic remains identical after optimization.”article, stated

Early accuracy leaves the system as an assistant, not an autonomous optimizer.

Root cause: The launch reports about 25% accuracy, so GPT is useful but not reliable enough to replace human and test review.

Resolution: Keep recommendations reviewable in the MR and continue improving prompts, test cases, and real-world production evaluation.

“accuracy has reached around 25%, reflecting growing confidence in the tool among developers and dbdevs.”article, stated
“building a test framework that makes it easier for dbdevs to add test cases and fine-tune prompts”article, stated

Evaluation

Agoda evaluates the workflow through CI/CD performance tests, original-versus-optimized performance comparisons in MRs, reported accuracy after launch, and planned logic-verification and production high-CPU SP evaluation.

Metrics: approximately 366 man-days per year spent on SP optimization · 320 man-days spent on performance test failures · 90th percentile MR approval time of 4.1 hours · around 25% accuracy after launch · side-by-side performance comparison between original and GPT-optimized SP

3 supporting quotes
“Each year, our dbdevs spend approximately 366 man-days on SP optimization, 320 of those on performance test failures alone.”article, stated
“The summary result includes a performance comparison between the original SP and the GPT-optimized version.”article, stated
“accuracy has reached around 25%, reflecting growing confidence in the tool among developers and dbdevs.”article, stated

Outcomes

The system targets a yearly workload of roughly 366 dbdev man-days spent on SP optimization, including 320 man-days on performance test failures, with 90th percentile MR approvals reaching 4.1 hours before/around the intervention.

3 supporting quotes
“By incorporating GPT into this workflow, we’ve achieved the following benefits:”article, stated
“Improved SP Quality: GPT’s actionable suggestions enhance the performance and efficiency of stored procedures.”article, stated
“In parallel, we plan to identify high-CPU stored procedures from production and evaluate GPT’s impact on real-world performance.”article, stated