SQL Pivot Staging Table for Query Complexity Reduction

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing SQL pivot operations are inefficient due to complex queries and unnecessary data accesses, as they often rely on rewriting pivoting queries using group-by and aggregation operations, leading to suboptimal performance.

Innovation Solution

The approach involves creating staging tables to pivot and aggregate data using a single scan of the data table, optimizing memory usage by allocating only one row for unique combinations of grouping columns, and using equivalent queries to select the most efficient execution plan based on factors like memory usage.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of manufacture

If pivoting queries are rewritten using group-by and aggregation operations, then the query can be executed using existing SQL constructs, but the query becomes too complex and causes unnecessary data accesses and computations

Engineering Contradiction:
Improvequery executabilityVSAvoidquery complexity
Core Design Contradiction:
Ease of manufactureVSDevice complexity

Solution Approach 1:

The patent introduces a staging table as an intermediary structure between the source table and the final pivot result. The staging table receives data from the source table, performs aggregation operations there, and then provides the aggregated data for pivot operation. This intermediary approach simplifies the overall query structure by separating the aggregation and pivot operations into distinct phases, avoiding the complexity of trying to express pivot operations directly using group-by and aggregation constructs.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Ease of manufacture

If pivoting queries are rewritten using group-by and aggregation operations, then the query can be executed, but unnecessary data accesses and computations are performed

Engineering Contradiction:
Improvequery executabilityVSAvoidquery execution efficiency
Core Design Contradiction:
Ease of manufactureVSProductivity

Solution Approach 1:

The patent performs preliminary aggregation operations on the source table data before the pivot operation occurs. By pre-aggregating the data in the staging table, the system avoids unnecessary data accesses and computations during the pivot operation itself. The staging table is populated with aggregated data in advance, so when the pivot operation runs, it only needs to process the pre-aggregated data, significantly improving execution efficiency.

Inventive Principle:
Principle #10Preliminary action

3Reliability

If staging tables are created with multiple rows for unique combinations of grouping columns, then all data combinations can be stored, but memory usage increases

Engineering Contradiction:
Improvedata storage completenessVSAvoidmemory usage
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

The patent applies local quality optimization by creating staging table rows only for unique combinations of grouping column values that actually exist in the source data. Instead of creating a staging table with rows for all possible combinations (which would waste memory), the system creates rows only for the actual unique combinations present in the data, optimizing memory usage while maintaining data storage completeness for the relevant cases.

Inventive Principle:
Principle #3Local quality

Data Source

PatentUS8041731B2Efficient evaluation of SQL pivot operations
Publication Date: 2011.10.18 ORACLE INT CORP
  • US8041731B2 patent drawing
  • US8041731B2 patent drawing
  • US8041731B2 patent drawing

AI summary

Techniques are described herein for supporting efficient evaluation of pivot operations. In an embodiment, a pivoting query on a data table is received. The query identifies pivot columns, measure columns, and grouping columns. In response to receiving the query, a staging table that comprises new pivot columns, aggregated columns, and new grouping columns may be created. For each particular unique combination of values of the grouping columns and the pivot columns in the data table, stored values in the measure columns in the data table are aggregated for certain rows in the plurality of rows in the data table. Each row of the certain rows comprises the each particular unique combination of values of the grouping columns and the pivot columns in the data table. Results of aggregating are stored in the staging table. Data that has been populated in the staging table is transposed into a result set.