{"id":25819033,"url":"https://github.com/pngo1997/sql-query-optimization-precedence-graph-analysis","last_synced_at":"2026-05-16T05:12:00.105Z","repository":{"id":275042007,"uuid":"924886116","full_name":"pngo1997/SQL-Query-Optimization-Precedence-Graph-Analysis","owner":"pngo1997","description":"Explores SQL query execution, indexing, and serializability in database transactions using SQLite and Python.","archived":false,"fork":false,"pushed_at":"2025-01-30T20:40:09.000Z","size":2887,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T14:13:31.570Z","etag":null,"topics":["index","python","sql","sqllite","text-processing"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pngo1997.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-30T20:25:30.000Z","updated_at":"2025-01-30T20:40:12.000Z","dependencies_parsed_at":"2025-01-30T21:37:20.351Z","dependency_job_id":null,"html_url":"https://github.com/pngo1997/SQL-Query-Optimization-Precedence-Graph-Analysis","commit_stats":null,"previous_names":["pngo1997/sql-query-optimization-precedence-graph-analysis"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pngo1997/SQL-Query-Optimization-Precedence-Graph-Analysis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pngo1997%2FSQL-Query-Optimization-Precedence-Graph-Analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pngo1997%2FSQL-Query-Optimization-Precedence-Graph-Analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pngo1997%2FSQL-Query-Optimization-Precedence-Graph-Analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pngo1997%2FSQL-Query-Optimization-Precedence-Graph-Analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pngo1997","download_url":"https://codeload.github.com/pngo1997/SQL-Query-Optimization-Precedence-Graph-Analysis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pngo1997%2FSQL-Query-Optimization-Precedence-Graph-Analysis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285903256,"owners_count":27251121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-23T02:00:06.149Z","response_time":135,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["index","python","sql","sqllite","text-processing"],"created_at":"2025-02-28T08:14:25.862Z","updated_at":"2025-11-23T05:03:10.771Z","avatar_url":"https://github.com/pngo1997.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🏗️ SQL Query Optimization \u0026 Precedence Graph Analysis  \n\n## 📜 Overview  \nThis project explores **SQL query execution, indexing, and serializability in database transactions** using **SQLite** and **Python**. It includes **performance benchmarking**, **SQL vs. Python query execution time comparisons**, and **precedence graph analysis** for database scheduling.  \n\n## 🎯 Problem Explanation  \n\n### **Part 1: Query Execution and Performance Benchmarking**  \nThis section compares **SQL query execution** with equivalent **Python-based queries** and measures **runtime performance**.  \n\n#### **1. Expanding the Database Schema**  \n- Created a **new Geo table** in addition to the existing `Tweet` and `User` tables.  \n- The `Geo` table includes:  \n  - **Primary Key (`geo_id`)** – Assigned based on location uniqueness.  \n  - **Type**  \n  - **Longitude**  \n  - **Latitude**  \n- **Linked `Geo` table to the `Tweet` table** via **foreign key**.  \n\n#### **2. Query Execution \u0026 Benchmarking**  \n- **SQL Query Execution \u0026 Timing:**  \n  a. Find tweets where **tweet ID (`id_str`) contains \"89\" or \"78\"** anywhere in the column.  \n  b. Find the number of **unique values in the `friends_count` column**.  \n\n- **Equivalent Python-Based Query Execution \u0026 Timing:**  \n  - Queries executed **without using SQL** by reading from the **CSV file**.  \n  - Execution time compared against **SQL query performance**.  \n\n#### **3. Visualization (Scatter Plot)**  \n- Plotted **tweet lengths (first 60 tweets) vs. username lengths**.  \n- Created a **scatterplot** to analyze correlation.  \n\n### **Part 2: Query Optimization Using Indexes \u0026 Materialized Views**  \nThis section improves query performance using **indexes and materialized views** in **SQLite**.  \n\n- **Indexes Created:**  \n  a. **Index on `userid`** in the `Tweet` table.  \n  b. **Composite index on (`friends_count`, `screen_name`)** in the `User` table.  \n- **Materialized View for Query Optimization:**  \n  - Since SQLite lacks **materialized view support**, created an **optimized table (`CREATE TABLE AS`)** to store precomputed query results for **faster retrieval**.  \n\n### **Part 3: Precedence Graph \u0026 Serializability Analysis**  \nThis section evaluates **database transaction schedules** for **conflict serializability** using **precedence graphs**.  \n\n- **Precedence Graph for Schedule 1:**  \n  - The schedule is **serializable**.  \n  - **Equivalent Serial Schedule:** `\u003cT3, T1, T2\u003e`.  \n\n- **Precedence Graph for Schedule 2:**  \n  - The schedule is **NOT serializable** due to a **conflict schedule**.  \n\n## 🚀 Technologies Used  \n- **SQLite** (for database management \u0026 indexing).  \n- **Python (Pandas, Matplotlib)** (for data querying, visualization \u0026 performance benchmarking).  \n- **SQL Query Optimization** (Indexes \u0026 Materialized Views).  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpngo1997%2Fsql-query-optimization-precedence-graph-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpngo1997%2Fsql-query-optimization-precedence-graph-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpngo1997%2Fsql-query-optimization-precedence-graph-analysis/lists"}