LEARN WITH ABDOU / LAB 12 REFACTOR AND TUNE
Original fictional data. The official assignment uses duluth_market.db from Canvas.

TWO DATABASES, TWO PURPOSES
harbor_market.db: 3 vendors, 4 products, 4 orders, 6 lines, 0 audit rows.
  Small enough to verify every business rule. Integer cents; dates YYYY-MM-DD.
  No triggers or extra indexes are installed initially. Stock is a present snapshot;
  historical lines were loaded before the insertion triggers are created.
benchmark.db: 1200 orders and 7200 lines. A separate generated workload.
  It has no vendor, product, refund or stock semantics. product_id is a synthetic
  lookup attribute, not a declared FK. Do not mix its totals with the small market.

START
Extract the kit. Keep the original files and make working copies in this folder.
Use modern SQLite (3.25+ for alignment with the full course).
Run SELECT sqlite_version(); and PRAGMA foreign_keys=ON; in each new connection.
Questions 1–5 use fresh market copies. Question 6 uses a fresh benchmark copy.

SMALL MARKET
Read baseline.sql; refactor.sql is a worked CTE version for comparison.
calendar.sql supplies a bounded recursive calendar and zero-month example.
audit.sql, inventory.sql, refunds.sql install the teaching triggers. Install each
only when the question asks, once per fresh copy. Candidate faulty triggers are
on the website: compare them on different copies so rules do not overlap.
Run error demonstrations one statement at a time in the SAME connection.
After an error inspect pending data BEFORE ROLLBACK, then inspect again.
The insertion stock rules do not define editing/deleting lines or refund restocking.

TIMING (SQLite shell, not a browser SQL textarea)
From a terminal in this extracted folder, open your copied benchmark:
  sqlite3 timing-copy.db
At the sqlite> prompt:
  .read benchmark.sql
  .read composite.sql
benchmark.sql prints plans and three timed runs before/after creating the order
index, then demonstrates two date predicates. composite.sql expects benchmark.sql
to have finished; it replaces the order index and tests three lookup predicates.
Do not rerun these setup-changing scripts in the same used file. Make a fresh copy.
Record actual timings, version, exact query, row counts and plans. Compare medians.
If output rounds to zero or noise dominates, report inconclusive. No fixed speedup
is promised. Planner choices vary with SQLite version and statistics.

REBUILD (optional; unused database filenames, no deletion required)
  sqlite3 fresh-market.db
  .bail on
  .read setup.sql
  .quit
Or for the benchmark:
  sqlite3 fresh-benchmark.db
  .bail on
  .read benchmark-setup.sql
  .quit
Dot commands run inside sqlite3, not the browser SQL editor.

WORKSHOP: https://learnwithabdou.com/courses/mis3220/labs/refactor-tune
OFFICIAL LAB: https://learnwithabdou.com/courses/mis3220/labs/lab-12
Use Canvas question numbers, findings, Check the AI, client task and individual
reflections in the official report. Nothing in this kit submits to Canvas.
