system.interfaces.query_processing.query_processing module

Abstract query-processing interfaces: QEP, queryable components, and query optimizer.

class system.interfaces.query_processing.query_processing.QEP[source]

Bases: ABC

Query Execution Plan

class system.interfaces.query_processing.query_processing.QEPQueryable[source]

Bases: ABC

A simplified interface of a component that can be queried using a QEP. In other words, a component that can execute a query execution plan.

abstractmethod execute_query(qep: QEP, TA_ID: int | None = None) → Iterator[object][source]

Execute a query execution plan.

Parameters:
  • qep – The query execution plan to execute

  • TA_ID – The TA_ID of the transaction that is executing the query. If not provided, the query is executed as a separate transaction, i.e. it will automatically be wrapped into a transaction.

Returns:

The result of the query as an Iterator of objects. The objects can be of any type.

class system.interfaces.query_processing.query_processing.QueryableComponent[source]

Bases: ABC

A component that can be queried using textual queries. In other words, a component that can execute queries.

abstractmethod execute_unprepared_query(query: str, TA_ID: int | None = None) → Iterator[object][source]

Execute a query, non-prepared version on a textual query string. DO NOT USE THIS METHOD. Only provided for backward compatability or cases where sanitizing the query is not required or done outside the DBMS.

Parameters:
  • query – The query to execute as a string. Technically, we are not specifying the query language at this point.

  • TA_ID – The TA_ID of the transaction that is executing the query. If not provided, the query is executed as a separate transaction, i.e. it will automatically be wrapped into a transaction.

Returns:

The result of the query as an iterator of objects. The objects can be of any type.

Deprecated since version Use: the prepare_query function instead!

prepare_query(query: str, parameters: list[str]) → int[source]

Prepare a query to be executed multiple times with different parameters.

Parameters:
  • query – The query to execute as a string. Technically, we are not specifying the query language at this point.

  • parameters – The parameters to use in the query

Returns:

The id of the prepared query. This id can be used to execute the query multiple times with different parameters using method :func execute_prepared_query.

abstractmethod execute_prepared_query(query_id: int, parameters: dict[str, object], TA_ID: int | None = None) → Iterator[object][source]

Execute a query, prepared version. Always use this method to execute a query.

Parameters:
  • query_id – The id of the prepared query to execute

  • parameters – The parameters to use in the query

  • TA_ID – The TA_ID of the transaction that is executing the query. If not provided, the query is executed as a separate transaction, i.e. it will automatically be wrapped into a transaction.

Returns:

The result of the query as an iterator of objects. The objects can be of any type.

class QueryEntry(parameters: dict[str, object], TA_ID: int = None)[source]

Bases: object

A dataclass to hold the parameters of a prepared query and the transaction id of the transaction that is executing the query. This is used to execute multiple prepared queries with different parameters as a batch.

parameters: dict[str, object]
TA_ID: int = None
execute_prepared_queries(queries: dict[int, QueryEntry]) → dict[int, Iterator[object]][source]

Execute multiple prepared queries with different parameters as a batch. Useful for multi-query processing and optimization (MQO). For the moment, we simply call the method :func execute_prepared_query for each query id, parameters, and TA_ID. However, this method can be overwritten to do real MQO.

Parameters:

queries – A dictionary of prepared query ids and QueryEntries. The keys are the query ids and the values is the QueryEntry for this prepared query.

Returns:

A dictionary of query ids and the result of the query as an iterator of objects. The objects can be of any type.

class system.interfaces.query_processing.query_processing.QueryOptimizer[source]

Bases: ABC

Query Optimizer interface

abstractmethod create_QEP(query: str) → QEP[source]

Create a query execution plan (QEP) from the query string. :param query: The query to create a plan for :returns: The QEP

abstractmethod prepare_query(query: str, parameters: list[str]) → QEP[source]

Prepare a query to be executed multiple times with different parameters. :param query: The query to prepare :param parameters: The list of parameters the query has. :returns: The query execution plan (QEP).

abstractmethod bind_parameters(prepared_query_QEP: QEP, parameters: dict[str, object]) → QEP[source]

Bind parameters to a prepared qep.

Parameters:
  • prepared_query_QEP – The QEP of the prepared query to bind parameters to

  • parameters – The parameters to bind

Returns:

The QEP with the parameters bound