Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Dynamic Table. #725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Commits on Nov 27, 2024

  1. Dynamic Table.

    Dynamic Table is a an auto-refreshing materialized view which could
    be constructed by base tables, external tables, materialized views
    and dynamic tables.
    And it could be used to answer query by AQUMV.
    As normal tables in CBDB, dynamic tables could also have distribution
    keys.
    
    The purpose of Dynamic Tables is to solve the problem often raised by
    customers who are big fans of a lakehouse architecture: how can we run
    queries on external tables as fast as internal tables?
    
    CREATE DYNAMIC TABLE:
    
    CREATE DYNAMIC TABLE dt0 SCHEDULE '5 * * * *' AS
      SELECT a, b, sum(c) FROM t1 GROUP BY a, b WITH NO DATA DISTRIBUTED
    BY(b);
    CREATE DYNAMIC TABLE
    
    \d
                     List of relations
     Schema | Name |     Type      |  Owner  | Storage
    --------+------+---------------+---------+---------
     public | dt0  | dynamic table | gpadmin | heap
     public | t1   | table         | gpadmin | heap
    (2 rows)
    
    CREATE DYNAMIC TABLE xxx AS Query
    The Query allows any valid SELECT SQL of Materialized Views: from single
    or multiple relations, base tables, materialized views, and dynamic
    tables as well, joins, subquery, aggregation, group by and etc.
    
    SCHEDULE:
    A string used to schedule background job which auto-refreshes the
    dynamic table.
    We follow the valid string of pg_cron extension which supports linux
    crontab, refer https://crontab.guru
    
     ┌───────────── min (0 - 59)
     │ ┌────────────── hour (0 - 23)
     │ │ ┌─────────────── day of month (1 - 31) or last day of the month ($)
     │ │ │ ┌──────────────── month (1 - 12)
     │ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday to
     │ │ │ │ │                  Saturday, or use names; 7 is also Sunday)
     │ │ │ │ │
     │ │ │ │ │
     * * * * *
    
    You can also use '[1-59] seconds' to schedule a job based on an
    interval.
    The example creates a cron job refreshing the dynamic table at minute 5
    of each hour.
    For convenience, SCHEDULE is optional. If user didn't specific it, a default
    schedule is provided: at every 5th minute.
    
    WITH NO DATA:
    Same as Materialized View, will create an empty Dynamic Table if
    specified.
    
    DISTRIBUTED BY:
    Same as normal tables in CBDB, Dynamic Tables could support distribution
    keys as materialized views.
    
    Refresh Dynamic Table
    As seen in pg_task, we put a command to auto-refresh dynamic tables.
    However, if users want to do a REFRESH manually, exec command REFRESH
    DYNAMIC TABLE is also supported.
    REFRESH DYNAMIC TABLE dt0;
    REFRESH DYNAMIC TABLE
    
    Refresh WITH NO DATA
    Same as Materialized Views, Refresh with no data will truncate the
    Dynamic Table and make it unpopulated status.
    REFRESH DYNAMIC TABLE dt0 WITH NO DATA;
    REFRESH DYNAMIC TABLE
    
    Drop Dynamic Table
    Drop a Dynamic Table will drop its scheduler job automatically.
    DROP DYNAMIC TABLE dt0;
    DROP DYNAMIC TABLE
    
    Like Materialized Views, Dynamic Tables could be used to answer query
    too. This is limited by AQUMV.
    
    Authored-by: Zhang Mingli [email protected]
    avamingli committed Nov 27, 2024
    Configuration menu
    Copy the full SHA
    ef1af11 View commit details
    Browse the repository at this point in the history