cwida/ivm-extension

Plan modification fails if view query contains filter that produces no data

kriti-sc opened this issue · 0 comments

Assume the following series of queries:

CREATE TABLE hello(a INTEGER, b VARCHAR, c VARCHAR); 
-- note that table hello has no data
CREATE VIEW test AS (SELECT SUM(a), COUNT(c), b FROM hello WHERE b = 'true' GROUP BY b);

PRAGMA ivm_upsert('memory', 'main', 'test');

The logical plan that we modify to incrementally maintain view test is for query SELECT SUM(a), COUNT(c), b FROM hello WHERE b = 'true' GROUP BY b. It will look like below, because the FILTER gets pushed down. This happens becausehello has no data, and also happens if the filter clause produces no data.

┌───────────────────────────┐
│         PROJECTION        │
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │
│           sum(a)          │
│          count(c)         │
│             b             │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│         AGGREGATE         │
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │
│             b             │
│     sum_no_overflow(a)    │
│        count_star()       │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│        EMPTY_RESULT       │
└───────────────────────────┘