Guided SQL-Based Data Exploration
Personalized, step-by-step SQL query recommendations learned online from user feedback with multi-armed bandits
Paper (ICDE 2024) Code on GitHub
Description
Overview
Instead of recommending full SQL queries, the user builds a query step by step, top-down, and a recommender helps at every step:
-
Table recommender suggests tables for the
FROMclause. -
Column recommenders suggest columns of the selected tables for the
SELECTandWHEREclauses. -
Predicate recommenders suggest filters on a chosen column:
-
categorical columns get
column = valuepredicates; -
numerical columns get
column BETWEEN x AND yregions, built with equal-width, equal-height or K-means binning.
-
categorical columns get
Breaking the problem up this way means each recommender picks from a small, finite pool of items (for example, only the columns of the tables already selected), rather than from every possible query.
Each recommender is a multi-armed bandit that returns the top-K items and learns online from which ones the user picks (any number, in any position). Feedback is implicit: the system reads it from the queries the user builds, so the user never rates anything. A selected item gets a reward of 1. For numerical regions, the reward is how much the recommended bin overlaps the region the user chose.
We design pUCB, a lightweight personalized variant of UCB that needs no user or item features. It ranks items by combining what the current user has picked before with what all users prefer, weighted by a personalization factor.
Key Results
Offline evaluation replays real query logs from the Sloan Digital Sky Survey (SDSS DR7: 115 tables, 52 views, 9,903 columns). We compare pUCB with UCB, Thompson Sampling, ε-greedy and a Popular baseline.
pUCB scores highest on every dataset and clause. MAP@K on the TH50 dataset:
| Clause | Popular | ε-greedy | TS | UCB | pUCB |
|---|---|---|---|---|---|
SELECT |
0.60 | 0.57 | 0.61 | 0.64 | 0.75 |
FROM |
0.45 | 0.40 | 0.44 | 0.45 | 0.64 |
WHERE |
0.56 | 0.50 | 0.53 | 0.58 | 0.69 |
User study. 17 participants used Query Builder (QB), a system built on this framework, on the CORDIS database of European research projects. Each did NL-to-SQL and data-navigation tasks, some with QB and some writing SQL by hand. They fully completed 90% of tasks with QB, compared with 70% by hand, and finished much faster. Every participant, including the SQL experts, said they preferred QB to writing SQL manually.
Code
The code, experiments and user study are available on GitHub.