Skip to content

Enable SQLITE_ENABLE_MATH_FUNCTIONS flag in SQLite build #5261

@renecannao

Description

@renecannao

Summary

SQLite's mathematical functions are disabled by default and require the SQLITE_ENABLE_MATH_FUNCTIONS compile-time flag to be enabled. This proposal enables this flag in ProxySQL's SQLite build configuration to provide users with access to mathematical functions in SQL queries through ProxySQL's SQLite interface.

Background

ProxySQL uses SQLite for:

  • Admin interface queries
  • Query rules processing
  • Statistics and monitoring data storage
  • Internal configuration storage

Currently, SQLite is compiled without SQLITE_ENABLE_MATH_FUNCTIONS, meaning functions like sin(), cos(), log(), pow(), sqrt(), etc., are unavailable in SQL queries.

Benefits

  1. Enhanced SQL Capabilities: Users can perform mathematical operations directly in SQL queries
  2. Statistical Calculations: Enable more complex query rules and data transformations
  3. Standard SQLite Feature: Aligns with SQLite's standard feature set
  4. No Breaking Changes: Purely additive functionality
  5. Minimal Impact: Small binary size increase (~few KB)

Functions Enabled

  • Trigonometric: sin(), cos(), tan(), asin(), acos(), atan()
  • Logarithmic: log(), log10(), ln()
  • Exponential: exp(), power()/pow()
  • Other: sqrt(), abs(), floor(), ceil(), round(), etc.

Implementation

Add -DSQLITE_ENABLE_MATH_FUNCTIONS to SQLite compilation flags in deps/Makefile:

# Current
-DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_JSON1 -DSQLITE_DLL=1

# Proposed  
-DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_JSON1 -DSQLITE_DLL=1 -DSQLITE_ENABLE_MATH_FUNCTIONS

Testing

  • Verify mathematical functions work in admin SQLite interface
  • Ensure backward compatibility with existing queries
  • Test sample queries using math functions

Related

This change has already been implemented in branch v3.0-misc251220 for evaluation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions