Database design and optimization with AI

Advanced AI-Assisted Coding for Developers

Thalia Barrera

AI Engineering Curriculum Manager, DataCamp

Plugging in real data

 

sql-table-error.png

 

  • New folder under Atlas's /usecase directory
  • sqlite3.OperationalError: no such table: activity_events
  • ❗ Table exists under a different name: schema mismatch
Advanced AI-Assisted Coding for Developers

AI for schema mapping

schema-mismatch.png

🤖 Schema alignment prompt:

Align my database schema to the schema Atlas needs to run. Use the tables from the production database and the tables Atlas expects. Rename tables and columns safely and list the mapping between the original data and the new schema.

Advanced AI-Assisted Coding for Developers

ai-table-squema.mp4

Advanced AI-Assisted Coding for Developers

Real-world data updates

mermaid: datacamp-purple: data reconciliation pipeline

 

  • Wayfarer ingests events from partners
  • Partners send duplicates, corrections, and adjustments
  • Stale data → inaccurate KPIs
  • Reconciliation through CRUD operations
Advanced AI-Assisted Coding for Developers

AI-assisted duplicate detection

 

  • Partners send new batches of booking events
  • Multiple providers scrape the same API → duplicates are common
  • Must detect duplicates before inserting into production

nanobanana: center: duplicate detection in database tables

Advanced AI-Assisted Coding for Developers

Designing the detection query

sql-duplication.png

Advanced AI-Assisted Coding for Developers

Query performance optimization

SQL query:

sql-innefficient-query2.png

🤖 Performance optimization prompt:

Here is an SQL query I run frequently, along with the table schema. Identify the main performance bottlenecks and rewrite the query to be more efficient without changing the results.

Advanced AI-Assisted Coding for Developers

ai-efficient-query.mp4

Advanced AI-Assisted Coding for Developers

Database design at scale

 

🤖 Database design prompt:

Given this schema and workload (frequent reads of KPIs by date and city, and daily batch inserts), recommend normalization improvements, partitioning strategies, and scaling options.

Prioritize changes with the best impact-to-effort ratio.

sql-data-growth.png

Advanced AI-Assisted Coding for Developers

ai-sql-partitioning.mp4

Advanced AI-Assisted Coding for Developers

Let's practice!

Advanced AI-Assisted Coding for Developers

Preparing Video For Download...