Skip to main content

SQL query preprocessor for generating optimized queries

Project description

sqlquerypp: SQL query preprocessor

sqlquerypp is a library for preprocessing SQL queries. Main purpose is writing highly optimized queries with a simplified syntax, allowing for both maintainability and high performance.

Limitations

Currently, only MySQL 8.4 syntax is supported.

Why preprocess SQL queries?

SQL (Structed Query Language) follows a declarative paradigm, i.e. a query explains "what should be done" not "how should it be done". This stands in contrast to imperative programming, which expresses the "how should a certain task be fulfilled" aspect.

Database systems' internals are responsible for maintaining this aspect. However, for certain and large data structures, writing down "naive" queries sometimes result in poor performance.

Supported performance optimizations

Combined UNION queries

Consider the following original query:

SELECT entity_b.*
FROM entity_b
INNER JOIN entity_a
  ON entity_a.id = entity_b.entity_a_id
  AND entity_a.criteria = 1337;

This is a very simplified example, but if you assume entity_b contains a multitude of items, even correct index conditions may exhaust any DBMS' join buffer.

If network overhead is acceptable, a fitting alternative approach could be a loop on the application side (Python pseudocode):

all_matches_in_entity_b = []
for entity_a_id in [rec.id
                    for rec in mysql_query("SELECT id FROM entity_a "
                                           "WHERE criteria = 1337")]:
    inner_result = mysql_query("SELECT * FROM entity_b "
                               f"WHERE entity_a_id = {entity_a_id}")
    all_matches_in_entity_b += inner_result

The following statement, which is invalid SQL, translates to a MySQL native construct of Recursive Common Table Expression and UNION fragments when compiled by sqlquerypp. This allows for maximal query performance, because the inner query with reduced complexity is still taken into account. At the same time, it grants minimal I/O overhead as only one query is executed on the database:

combined_result (SELECT id FROM entity_a WHERE criteria = 1337) AS $id {
    SELECT * FROM entity_b WHERE entity_a_id = $id;
}

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

sqlquerypp-0.1.0a6-cp314-cp314-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

sqlquerypp-0.1.0a6-cp314-cp314-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

sqlquerypp-0.1.0a6-cp313-cp313-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

sqlquerypp-0.1.0a6-cp313-cp313-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

File details

Details for the file sqlquerypp-0.1.0a6-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sqlquerypp-0.1.0a6-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 41ab8f636e5729a43048f00362d1d971105b5180e8e08001a2fa2f3b1344633d
MD5 37ecca635f076d307e4954645388b9c8
BLAKE2b-256 01d6ee4229c50c6f9ba297c6a4656f050428aa16e401bc319d5a87436e04b11b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlquerypp-0.1.0a6-cp314-cp314-musllinux_1_2_x86_64.whl:

Publisher: python-publish.yml on puzzleYOU/sqlquerypp

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

File details

Details for the file sqlquerypp-0.1.0a6-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sqlquerypp-0.1.0a6-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8489258287a58dba0a1f7dcfc70629e2b28245381eea21409e23ab22b32e78cb
MD5 1599b7bf949b610b7a00234012f1a435
BLAKE2b-256 1a934c0085a01ea0985f0337da9a4817ed70b84cfcf2ae5d0068973244045ced

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlquerypp-0.1.0a6-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on puzzleYOU/sqlquerypp

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

File details

Details for the file sqlquerypp-0.1.0a6-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sqlquerypp-0.1.0a6-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9163eefb7eeff1b1d5b4330f134b2a5d6fe9e4ba3726d12a77ada1b3c7fd46cb
MD5 63aa9f8a99dd9983885c7b53115363db
BLAKE2b-256 b40b6d9ae9d56843838235c74d6e65cc9f3c89d7efbb3e2017d397d966399eae

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlquerypp-0.1.0a6-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: python-publish.yml on puzzleYOU/sqlquerypp

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

File details

Details for the file sqlquerypp-0.1.0a6-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sqlquerypp-0.1.0a6-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6fe621fedb3819d8a2b0b987ec05b0a2afcd9b0f6f41ecd37be977040be70370
MD5 01c53b1b9be338f9ed87f72f2c3f8591
BLAKE2b-256 33f8479729c6a063d20317f0a2f1d36c3a995fa4e815dc352e239d4637786373

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlquerypp-0.1.0a6-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on puzzleYOU/sqlquerypp

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