OCP MySQL 8.0 Database Developer Free Sample Questions

20 free sample questions200 in the full practice test

Try simulator

1Z0-909 Sample Questions

  1. Question 1

    A financial services application is experiencing deadlocks during high-concurrency periods. The problematic transaction involves updating a user's balance and inserting a record into a transaction log table. The database uses the default REPEATABLE READ isolation level. Analysis reveals that two concurrent transactions often attempt to lock the same range of rows in the transaction log table, which is indexed by transaction_date. Which strategy is most effective at resolving these deadlocks while maintaining data consistency?

    Answer and explanation

    Correct answer: A

    Changing the isolation level to READ COMMITTED for these specific transactions is the best solution. REPEATABLE READ uses gap locks, which can lock the space between index records, leading to a higher chance of deadlocks when inserting into a sequentially indexed column. READ COMMITTED does not use gap locks for ordinary statements, which significantly reduces the likelihood of this type of deadlock. Switching to SERIALIZABLE would worsen the problem by increasing locking. Using LOCK TABLES is too coarse and would serialize access, killing concurrency. Retrying transactions is a valid strategy but doesn't solve the root cause of the frequent deadlocks.

  2. Question 2

    A developer is building a feature to store user preferences as JSON objects in a user_profiles table. The application needs to update a specific nested attribute (theme.color) and add a new attribute (notifications.enabled) in a single atomic operation. The existing JSON is: {"theme": {"color": "dark"}, "font_size": 14}. Which MySQL function should be used to achieve this?

    Answer and explanation

    Correct answer: B

    JSON_MERGE_PATCH is the correct function. It follows RFC 7396 semantics, where it recursively merges JSON documents. It updates existing key values and adds new key-value pairs. In this case, it would update theme.color and add notifications.enabled. JSON_SET can update existing values and add new ones, but requires specifying each path and value pair individually, making it less concise for merging objects. JSON_REPLACE only updates existing values and does not add new ones. JSON_MERGE_PRESERVE would create an array if keys conflict, which is not the desired behavior here.

  3. Question 3

    A data analyst needs to generate a report showing the total sales for each product category, but only for categories with total sales exceeding $10,000. Which of the following query structures is correct?

    erDiagram PRODUCTS ||--o{ ORDER_ITEMS : contains CATEGORIES ||--o{ PRODUCTS : belongs to CATEGORIES { int category_id PK string category_name } PRODUCTS { int product_id PK int category_id FK string product_name decimal price } ORDER_ITEMS { int item_id PK int product_id FK int quantity }

    Answer and explanation

    Correct answer: B

    The HAVING clause is used to filter groups after aggregation has been performed, whereas the WHERE clause filters rows before aggregation. To filter based on the result of an aggregate function like SUM(), you must use HAVING. The alias total_sales cannot be used in the WHERE clause of the same query level where it is defined.

  4. Question 4

    You are tasked with optimizing a slow query that retrieves user information. The EXPLAIN output shows that a full table scan is performed on the users table despite an index existing on the email column. The query is: SELECT user_id, name FROM users WHERE YEAR(created_at) = 2023 AND SUBSTRING(email, INSTR(email, '@') + 1) = 'example.com';. What is the primary reason the index on email is not being used?

    Answer and explanation

    Correct answer: C

    Applying a function like SUBSTRING() or INSTR() to an indexed column in the WHERE clause prevents the MySQL optimizer from using the index on that column. This makes the predicate non-SARGable (Search-Argument-able). To make the query use the index, the WHERE clause should be rewritten to compare the column directly, for example, WHERE email LIKE '%@example.com'. Note that even with LIKE, a leading wildcard (%) can also prevent index usage, but the function application is the definite cause here.

  5. Question 5

    Multiple answers

    A developer needs to create a stored procedure that accepts an employee ID and returns their department name and manager's name. Which parameter modes should be used for the department name and manager's name? (Select TWO)

    Answer and explanation

    Correct answers: B, E

    The OUT parameter mode is used for parameters that the procedure will set and return to the caller. Since the procedure needs to return the department name and manager's name, these should be OUT parameters.

    While using OUT parameters is one way to return values, a common and often preferred method for returning tabular data (even a single row with multiple columns) is to have the stored procedure execute a SELECT statement. This produces a result set that the calling application can then process.

  6. Question 6

    True or False: In MySQL 8.0, using the JSON_TABLE() function, you can project a JSON document into a relational table format within a single query, which can then be joined with other standard relational tables.

    Answer and explanation

    Correct answer: A

    This statement is true. The JSON_TABLE() function is a powerful feature in MySQL 8.0 that allows you to extract data from a JSON document and present it as a relational table with specified columns and data types. This resulting virtual table can be used in the FROM clause of a query and joined with other physical or virtual tables.

  7. Question 7

    An e-commerce company, "GlobalCart," is migrating its product catalog to a MySQL 8.0 database. The catalog data for each product is semi-structured and received from various suppliers as JSON documents. A key requirement is to allow flexible schema changes without database migrations, while also supporting high-performance filtering on specific attributes like price and brand_id which are nested deep within the JSON. The development team is also building a new set of microservices that will interact with this data using modern, fluent APIs rather than raw SQL strings.

    The current table is defined as CREATE TABLE products (id INT PRIMARY KEY, doc JSON);. Initial performance tests show that queries filtering on price, such as SELECT * FROM products WHERE JSON_EXTRACT(doc, '$.details.price') < 50;, are very slow because they require a full table scan and JSON parsing for every row.

    Which solution best meets GlobalCart's requirements for schema flexibility, query performance, and modern API access?

    Answer and explanation

    Correct answer: C

    This is the optimal solution. Using the MySQL Document Store and XDevAPI directly addresses all requirements. It maintains schema flexibility (NoSQL model), provides high-performance filtering by allowing indexes on nested JSON fields, and offers a modern, fluent API (XDevAPI) for microservice development. While adding generated columns (Option B) solves the performance issue, it doesn't address the need for a modern API and ties the schema more tightly to relational concepts. The other options are significantly less performant and scalable.

  8. Question 8

    A developer needs to connect a new Python application to a MySQL 8.0 database. The requirements are to use an official, pure Python driver that supports the new X Protocol for Document Store access. Which connector should be chosen?

    Answer and explanation

    Correct answer: A

    MySQL Connector/Python is the official Oracle driver for Python. It is a pure Python implementation and provides support for both the classic MySQL protocol and the new X Protocol, which is required for interacting with the MySQL Document Store via the XDevAPI.

  9. Question 9

    You need to design a view that summarizes customer order totals. The view should prevent any direct INSERT or UPDATE operations that would result in a customer having a negative total order value. How can this constraint be enforced through the view definition?

    Answer and explanation

    Correct answer: B

    The WITH CHECK OPTION clause is used to enforce the conditions in the view's WHERE clause for any INSERT or UPDATE statements performed through the view. If the view is defined with WHERE total_order_value >= 0, adding WITH CHECK OPTION will cause any modification that violates this condition to fail. However, a view with aggregation (SUM) is not updatable, so this option would only work on an updatable view. In a non-updatable view scenario, a trigger would be the only way.

  10. Question 10

    Multiple answers

    A batch import process is inserting millions of rows into an InnoDB table within a single transaction. The process is consuming excessive memory and UNDO log space, occasionally causing the server to run out of resources. Which TWO actions can mitigate this issue without sacrificing the all-or-nothing nature of the import? (Select TWO)

    Answer and explanation

    Correct answers: A, B

    Processing the import in smaller batches reduces the size of each individual transaction. This prevents the UNDO log from growing excessively and reduces memory consumption per transaction.

    Committing after each smaller batch finalizes that part of the work, allowing MySQL to reclaim the UNDO log space and other resources used by that transaction. This combination of batching and committing is a standard pattern for large data loads.

Register free to unlock 10 more sample questions

Lifetime One

Own this practice test forever.

$79.99
$75.99
one-time
  • Full access to 200 questions
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • Brainy AI Assistant
  • Lifetime updates

Two

Any 2 exams per month.

$20.00/exam
$39.99
/month
  • 2 active exam slots
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • 1,000 Brainy AI Credits
  • Cancel anytime

Premium Twelve

Any 12 exams over 3 months.

$15.00/exam
$179.99
/3 months
  • 4 active exam slots
  • Study, Timed & Flashcard Modes
  • All past and future versions i
  • Detailed Explanations
  • Study Tracking & Past Attempts
  • 15,000 Brainy AI Credits
  • Dedicated support
  • Friend seat included — full access

Trusted by professionals at

NvidiaSupabaseGitHubOpenAITursoClerkClaude AIAmazon