Skip to main content

DecidB - DuckDB with DECIDE clause for optimization queries

Project description

DeciDB

Optimization, Native in SQL

DeciDB extends SQL with the DECIDE clause for declarative in-database optimization. Express Integer Linear Programming (ILP) problems directly in SQL — no external solvers, no data export, no context switching.

A research project by HUDA Lab at NYU Abu Dhabi.

Quick Example

Traditional approach — export data, build a model in Python, solve, map results back:

import duckdb, pulp

items = conn.execute("SELECT id, value, weight FROM Items").fetchall()
prob = pulp.LpProblem("knapsack", pulp.LpMaximize)
x = [pulp.LpVariable(f"x_{i}", cat='Binary') for i in range(len(items))]
prob += pulp.lpSum(x[i] * items[i][2] for i in range(len(items))) <= 50
prob += pulp.lpSum(x[i] * items[i][1] for i in range(len(items)))
prob.solve()
# ... then map results back to database

With DeciDB — one SQL query:

SELECT id, value, weight, x
FROM Items
WHERE category = 'electronics'
DECIDE x IS BOOLEAN
SUCH THAT
    SUM(x * weight) <= 50
MAXIMIZE SUM(x * value);

Same result, a fraction of the code.

Installation

pip install decidb

Usage

import decidb

# Connect (in-memory or file-based)
conn = decidb.connect()

# Create data
conn.execute("""
    CREATE TABLE Items (id INTEGER, value INTEGER, weight INTEGER);
    INSERT INTO Items VALUES (1, 100, 20), (2, 60, 10), (3, 120, 30);
""")

# Run an optimization query
result = conn.execute("""
    SELECT id, value, weight, x
    FROM Items
    DECIDE x IS BOOLEAN
    SUCH THAT
        SUM(x * weight) <= 50
    MAXIMIZE SUM(x * value)
""").fetchall()

print(result)

The DECIDE Clause

DeciDB adds the DECIDE clause to standard SQL:

SELECT columns
FROM table
DECIDE variable [IS type], ...
SUCH THAT
    constraint AND ...
MAXIMIZE | MINIMIZE SUM(objective)

Decision Variable Types

Type Domain Example
IS BOOLEAN {0, 1} Select/skip an item
IS INTEGER {0, 1, 2, ...} Quantity to assign

IS INTEGER is the default if no type is specified.

Constraints

  • Arithmetic: SUM(x * weight) <= 50
  • Multiple constraints separated by AND
  • Conditional constraints: SUM(x * weight) <= 50 WHEN category = 'A'
  • Supported operators: =, <>, <, <=, >, >=

Objective

MAXIMIZE SUM(x * value)
MINIMIZE SUM(x * cost)

All expressions involving decision variables must be linear.

Use Cases

  • Knapsack / inventory selection — maximize value under weight or budget constraints
  • Portfolio optimization — select assets maximizing return under risk limits
  • Resource allocation — assign resources to tasks within capacity constraints
  • Meal planning — choose items optimizing nutrition within calorie budgets

Key Features

  • Native SQL — no context switching between query and optimization languages
  • Zero data movement — solve directly on database buffers
  • Declarative — define what to optimize, not how
  • Embedded solver — powered by HiGHS, a high-performance LP/MIP solver

Documentation

Research

DeciDB builds on a decade of research into in-database constrained optimization:

  • Scalable Package Queries in Relational Database Systems — Brucato, Abouzied, Meliou (VLDB 2016)
  • Scalable Computation of High-Order Optimization Queries — Brucato, Abouzied, Meliou (CACM 2019)
  • Scaling Package Queries to a Billion Tuples — Mai, Wang, Abouzied, Brucato, Haas, Meliou (VLDB 2024)

License

MIT License. See LICENSE for details.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decidb-0.1.0.tar.gz (12.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

decidb-0.1.0-cp313-cp313-win_amd64.whl (27.6 MB view details)

Uploaded CPython 3.13Windows x86-64

decidb-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

decidb-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (32.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

decidb-0.1.0-cp312-cp312-win_amd64.whl (27.6 MB view details)

Uploaded CPython 3.12Windows x86-64

decidb-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

decidb-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (32.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

decidb-0.1.0-cp311-cp311-win_amd64.whl (27.6 MB view details)

Uploaded CPython 3.11Windows x86-64

decidb-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

decidb-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (32.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file decidb-0.1.0.tar.gz.

File metadata

  • Download URL: decidb-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for decidb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 114e33c9aab618c0369ebd7a3885e0691c0249e61d7311504e6bf99d27c6765a
MD5 3632a7abbf40a09e291cebcf22d216b9
BLAKE2b-256 797276763b2fbbb58ba07579b1ee3d7d1dab1d1d2aad88daee27a64b7cd13ba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0.tar.gz:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: decidb-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 27.6 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for decidb-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 deaecd0c5dd984a185983be09f2bd99d7af2dcbdfc50ddd3cdbabb7a2fb5bb35
MD5 ef2fce7f28759d62036be4301c82d902
BLAKE2b-256 8c8762f106d8a1885c1916108f88a13a02ba22ed5e689700e103c789af63278e

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for decidb-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af1de0594b3769d24b1bbafc90a229af0729d50d2cf1e21a1cf7f9f47c9492a2
MD5 8d72bb8dfd7f534500335e208dfd21e1
BLAKE2b-256 f464d874333630a2361874fbae35b9804f444fb61e572eff4523298a28b1c5f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for decidb-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 820bea874934a980d28120278ed05449b8e91e3f3fad775f2bf45954fa9d8457
MD5 f3ee63b47f3b7cca082d6874da7a401f
BLAKE2b-256 366c28c24467ca3fab6103950914122ad1f032a77761eec9a2c5b6305bf45c14

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: decidb-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 27.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for decidb-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3bd5b6036ada50e1d52ea68ddc55141cec0676ad082667640d97b087dc66daac
MD5 f5af91a6ad7fd59360a4590dc767621f
BLAKE2b-256 b1ac661d93a971da56bb09c3d0a5f655c0130ac71c708fe6dc5f35c408706ddc

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for decidb-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9851f48aca3f03e3bf282a004595f3c75bf7d82f99dd04beea9f195cf990c30c
MD5 b79b43b0712ae8cbba5e80ffea12f180
BLAKE2b-256 0ddd2850bc1269db3174469c6b140fea9b42bbbbe603f8099a1897ba5c87a331

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for decidb-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1e475573980128dd4c6836d7e736f1fec88b5d4fd2a483211ee35910ffc6f52
MD5 4d088d605ff54fb5c9cce8d9f96d6d4d
BLAKE2b-256 f3fb5c66a257f4f657d1a005f29c226c98e63e4f2ecd63ef5da34933db7cee44

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: decidb-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 27.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for decidb-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c1f40d5895d42bc8b2c52f618e26750d139039e6ffd1c2a334e0dac744670546
MD5 ee4760e5442fe199bd1a0d0cdf1a1eb2
BLAKE2b-256 b639ff7a76a85ad3d43da104c632f2ac2dadc2782fa0140f65c85c23af2d526d

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for decidb-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f97185bf936cbaa84a28ee6089ab6cb89c1fc05b4362ff60ee7f68a04d5c41ef
MD5 2ea852711bc99f0c55898e381420c6c0
BLAKE2b-256 59567363931336861af9d1ccf5f70ddbf164b9e42c3ad2fd3400c11926563045

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file decidb-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for decidb-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6e89a5445f06c1178e052432af6bb992c75df0ef3f5f8f349d52f1a5139959b
MD5 c8515c1bd703e2001f46a9f72dee1954
BLAKE2b-256 59cd813be09cdb4b37443118f66c37169cc7d74f6ddd3df91069ca880b9b9592

See more details on using hashes here.

Provenance

The following attestation bundles were made for decidb-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on huda-lab/decidb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page