Question 329 of 503
Monitor and optimize database performanceeasyMultiple ChoiceObjective-mapped

Quick Answer

The answer is to create a composite index on `(user_id, created_at)`. This is correct because when a slow query in Cloud SQL for PostgreSQL performs a sequential scan, it often lacks an index that supports both the filter and the sort order. A composite index on `(user_id, created_at)` enables the database to first seek the exact `user_id` via an index seek, then efficiently access rows in `created_at` order, eliminating the need for a costly sequential scan and separate sort operation. On the Google Professional Cloud Database Engineer exam, this scenario tests your understanding of composite index optimization for slow queries in Cloud SQL, specifically how column order matters: place equality columns first, then range or sort columns. A common trap is creating separate single-column indexes, which PostgreSQL cannot combine as effectively for both filtering and ordering. Remember the mnemonic "Equal first, then range" to quickly recall the correct column order for composite indexes.

PCDE Monitor and optimize database performance Practice Question

This PCDE practice question tests your understanding of monitor and optimize database performance. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Network Topology
+Refer to the exhibit.```Database: mydbTable: orderscolumn | type | sizetotal | float| 8 bytesIndexes:"orders_pkey" PRIMARY KEY, btree (id)"idx_orders_user_id" btree (user_id)Query:Execution Plan:

Refer to the exhibit. You are analyzing a slow query in Cloud SQL for PostgreSQL. The execution plan shows a sequential scan. Which index should you create to most effectively improve query performance?

Question 1easymultiple choice
Full question →
Network Topology
+Refer to the exhibit.```Database: mydbTable: orderscolumn | type | sizetotal | float| 8 bytesIndexes:"orders_pkey" PRIMARY KEY, btree (id)"idx_orders_user_id" btree (user_id)Query:Execution Plan:

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

CREATE INDEX idx_orders_user_created ON orders(user_id, created_at);

Option D is correct because the query likely filters on `user_id` and then sorts or filters by `created_at`. A composite index on `(user_id, created_at)` allows PostgreSQL to first narrow down by `user_id` using index seek, then efficiently access rows in `created_at` order, avoiding a sequential scan. This matches the most common pattern for slow queries involving equality on `user_id` and range or ordering on `created_at`.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • CREATE INDEX idx_orders_partial ON orders(created_at) WHERE user_id = 123;

    Why it's wrong here

    Only helps for user_id 123; other users still see sequential scans.

  • CREATE INDEX idx_orders_created_at ON orders(created_at);

    Why it's wrong here

    Does not cover the equality condition on user_id.

  • CREATE INDEX idx_orders_created_user ON orders(created_at, user_id);

    Why it's wrong here

    Less efficient because range condition on created_at reduces index usefulness for user_id.

  • CREATE INDEX idx_orders_user_created ON orders(user_id, created_at);

    Why this is correct

    Allows index seek on user_id then range scan on created_at.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Google Cloud often tests the misconception that any composite index with the right columns will work, but the column order matters critically — candidates pick `(created_at, user_id)` thinking it covers both, not realizing the leading column must match the equality filter for optimal performance.

Detailed technical explanation

How to think about this question

PostgreSQL's B-tree index works best when the leading column matches equality conditions; placing `user_id` first enables index seek to a small subset of rows, then `created_at` provides sorted output without additional sort operations. In real-world scenarios, a query like `SELECT * FROM orders WHERE user_id = 123 ORDER BY created_at DESC` would benefit from this index, while a leading `created_at` index would require scanning all rows with that timestamp range and then filtering by `user_id`.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A company's IT admin needs to give a contractor read-only access to production logs without sharing account credentials. Using role-based access control (RBAC) and temporary scoped permissions — not a permanent shared password — is the correct pattern. Questions like this test whether you can apply least-privilege access across cloud identity services.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCDE practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCDE practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCDE question test?

Monitor and optimize database performance — This question tests Monitor and optimize database performance — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: CREATE INDEX idx_orders_user_created ON orders(user_id, created_at); — Option D is correct because the query likely filters on `user_id` and then sorts or filters by `created_at`. A composite index on `(user_id, created_at)` allows PostgreSQL to first narrow down by `user_id` using index seek, then efficiently access rows in `created_at` order, avoiding a sequential scan. This matches the most common pattern for slow queries involving equality on `user_id` and range or ordering on `created_at`.

What should I do if I get this PCDE question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on PCDE

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Your company runs a large e-commerce application on Google Cloud using Cloud SQL for MySQL (version 8.0) with 2 TB of data. The database experiences intermittent performance degradation during peak hours (10am-2pm). Cloud Monitoring shows a spike in CPU utilization to 90% and increased query latency. The database has been running for 6 months with default settings. You notice many slow queries like "SELECT * FROM orders WHERE customer_id=12345 ORDER BY order_date DESC LIMIT 10" that take 5-10 seconds. The orders table has 50 million rows, customer_id has a B-tree index, and order_date is not indexed. The query execution plan indicates a full table scan and a filesort. What is the most effective course of action to resolve the performance issue?

hard
  • A.Add a composite index on (customer_id, order_date)
  • B.Create multiple read replicas to offload read traffic
  • C.Partition the orders table by month using range partitioning
  • D.Increase the memory size of the Cloud SQL instance to 30 GB

Why A: The slow query uses a WHERE clause on customer_id (which is indexed) and an ORDER BY on order_date (not indexed). The index on customer_id alone is insufficient because the query still requires sorting, leading to a filesort. Adding a composite index on (customer_id, order_date) allows the database to retrieve rows for a specific customer in sorted order without a full scan or filesort. Option B (increasing memory) may help but does not address the root cause. Option C (read replicas) offloads read traffic but does not fix the query plan. Option D (partitioning) might help with data management but is not as direct or efficient as adding the appropriate index.

Variation 2. You are managing a Cloud SQL for MySQL instance that supports a web application. Recently, users have reported that the application is responding slowly during peak hours. You examine the Query Insights dashboard and see that a specific query is running frequently and has a high execution time. The query involves JOINs on three tables, each with tens of thousands of rows. The query plan shows a full table scan on two tables. What should you do first to improve performance?

easy
  • A.Enable the query cache flag in Cloud SQL database flags.
  • B.Increase the instance size to provide more memory and CPU.
  • C.Add indexes on the columns used in JOIN conditions.
  • D.Rewrite the query to use subqueries instead of JOINs.

Why C: Option C is correct: Adding appropriate indexes on the join columns will reduce full table scans, which is the most effective immediate action. Option A (increasing instance size) may help but does not address the root cause. Option B (enabling database flags like query cache) is less effective and query cache is deprecated in newer versions. Option D (rewriting the query) could help but is more complex and time-consuming; indexing is usually the first step.

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCDE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCDE exam.