Abstract
The integration of databases and machine learning promises to enhance various aspects of data management, analysis, and application. However, in-database machine learning (In-DB ML) is not easily portable to different database management systems and current approaches are typically limited to training and inference, while modern machine learning pipelines often involve aspects such as continuous learning, unlearning, and explainability. This paper presents BornSQL, a In-DB ML algorithm based on the Born Classifier [7], and exclusively implemented through standard SQL queries. BornSQL can handle categorical data, and it is particularly appropriate for classification of textual data. Further contributions of BornSQL are i) incremental learning to efficiently enforce model updates when new data become available in the db, ii) unlearning when selected data needs to be excluded due to privacy issues, and iii) global/local explainability to associate the importance of a feature/attribute in determining the classification result. We illustrate the usage and scalability of the algorithm using a benchmark database consisting of 2,359,828 scientific publications divided into three classes and composed of 3,942,559 features. The training time is linear in the number of publications and the average inference time for a publication is 1 millisecond on our experimental environment. We discuss potential applications such as cost-effective model serving, exploratory data analysis, and data privacy.
Introduction
Traditionally, In-Database Machine Learning (In-DB ML) has been a "hybrid" or "bolted-on" affair. Most solutions rely on User-Defined Functions (UDFs), which can be security risks and are rarely portable between different database systems. Furthermore, text classification is particularly difficult for databases because it requires heavy preprocessing that usually happens outside the database. This creates a "data gravity" problem: moving massive datasets out of a secure database into an ML environment is slow, expensive, and risky. BornSQL addresses this by implementing a powerful text classifier using nothing but standard SQL queries.
Methods
BornSQL is an implementation of the Born Classifier that treats database attributes as "words" in a document. It leverages sparse tensor representation within SQL tables to handle high-dimensional data efficiently.
Architecture and Lifecycle
The system supports the full ML lifecycle—including training, inference, incremental updates, and "unlearning" for privacy compliance—all within the relational engine.
As shown in the architecture diagram, BornSQL utilizes standard tables for features ($X_{nj}$), labels ($Y_{nk}$), and weights ($W_n$). Operations like FIT, PREDICT, and LOCAL EXPLAIN are executed as SQL queries that transform these tables.
Pure SQL Implementation
The core innovation is the use of standard SQL features like Common Table Expressions (CTEs), JOINs, and GROUP BY statements. This makes BornSQL highly portable across systems like PostgreSQL, MySQL, and SQLite.
The figure above illustrates how the mathematical foundations of the Born Classifier are mapped directly to SQL. For instance, weight calculations and probability distributions are derived through aggregations and joins, avoiding the need for external libraries.
Experimental Evaluation
The researchers evaluated BornSQL using several benchmarks, most notably a massive Scopus dataset containing 2,359,828 scientific publications with nearly 4 million features. The task was to classify papers into three subject areas: AI, Statistics, or Decision Sciences. Other datasets included the Adult dataset (UCI) and the RLCP dataset for record linkage.
Key Results
- Performance: On the Scopus dataset, the average inference time was just 1 millisecond per publication.
- Scalability: Training time was linear relative to the number of publications, demonstrating its suitability for large-scale data.
- Accuracy: BornSQL performed comparably to popular algorithms like Logistic Regression and Support Vector Machines (SVM) on standard benchmarks.
- Resource Efficiency: The entire 2.3-million-record experiment was successfully run on a standard laptop (MacBook Air M2), proving that In-DB ML does not necessarily require massive clusters.
Discussion and Conclusion
BornSQL demonstrates that complex ML tasks like text classification can be performed efficiently and portably using standard SQL. Its "unlearning" feature is particularly relevant for GDPR compliance, allowing a single SQL command to remove a user's data contribution without a full retrain. While currently limited to categorical data, BornSQL offers a robust framework for cost-effective model serving and privacy-preserving data analysis directly where the data lives.
Summary updated