Polymorphic Table Function Single Cursor Optimization
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The separation of cursors for outer SELECT statements and inner polymorphic table functions (PTFs) in SQL queries leads to suboptimal execution plans, resulting in excessive computational expense and inefficient data processing due to the inability to leverage cross-optimizations between the two.
Innovation Solution
Implementing a single cursor to handle both the outer SELECT statement and the inner PTF, allowing for cross-optimizations by rewriting portions of the inner PTF as a view within the outer SELECT statement, which enables the application of predicates from the outer statement to optimize the inner PTF's processing.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If separate cursors are used for outer SELECT statement and inner PTF, then cursor creation and processing is straightforward, but execution efficiency deteriorates due to inability to apply cross-optimizations
Solution Approach 1:
The patent merges the outer SELECT statement and inner PTF processing into a single cursor operation. Instead of creating separate cursors for the outer query and inner table function, the system combines them so that a single cursor handles both operations, enabling predicate pushdown and cross-optimizations that improve execution efficiency while maintaining manageable complexity through unified cursor management
2Productivity
If predicates are not applied to inner PTF, then PTF processing is simpler, but data processing expense increases due to processing unnecessary rows
Solution Approach 1:
The patent applies predicates to the inner PTF processing in advance, before the PTF executes its full data processing workflow. By pushing predicates down into the inner PTF operation, the system pre-filters the data that the PTF needs to process, eliminating unnecessary row processing and reducing computational expense while the complexity is managed through automated predicate pushdown mechanisms
Data Source
AI summary
Described is an approach for performing an efficient processing of table functions/polymorphic table functions. The approach does not create additional cursors for processing a table or polymorphic table function invoked within a SQL statement. Instead, the approach handles the SQL statement that invokes the table/polymorphic table function as a single cursor.


