当前位置:   article > 正文

pg创建物化视图--实现离线数据分析 之增量处理_gp库建物化视图增量

gp库建物化视图增量

  1. CREATE TABLE "public"."book" (
  2. "book_id" varchar(32) NOT NULL,
  3. "book_name" varchar(255) ,
  4. "book_price" float8,
  5. "book_type" varchar(255) ,
  6. "recordtime" timestamp(6),
  7. CONSTRAINT "book_pkey" PRIMARY KEY ("book_id")
  8. )
  9. ;
  10. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2000', '高中语文', 5.8, '教材', '2019-12-10 11:32:45');
  11. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2001', '高中语文', 5.8, '教材', '2019-12-10 11:32:45');
  12. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2002', '高中数学', 7.5, '教材', '2019-12-10 17:32:45');
  13. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2003', '高中英语', 10.5, '教材', '2019-12-10 17:33:45');
  14. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2004', '高中物理', 10, '教材', '2019-12-10 17:34:47');
  15. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2005', '高中化学', 10, '教材', '2019-12-10 17:34:47');
  16. -- 创建物化视图 根据实际逻辑替换下面 select sql即可 SELECT * FROM 函数;
  17. CREATE MATERIALIZED VIEW book_mv as SELECT * FROM PUBLIC.book;
  18. --必须要创建唯一索引才能增量刷新
  19. -- 在实际业务中 新增自增主键即可用于此: id serial8
  20. CREATE UNIQUE INDEX book_mv_index ON PUBLIC.book_mv(book_id);
  21. SELECT *FROM PUBLIC.book_mv;
  22. -- 源表新增一行
  23. INSERT INTO "public"."book"("book_id", "book_name", "book_price", "book_type", "recordtime") VALUES ('2006', '高中生物', 23, '教材', '2019-12-26 14:11:05');
  24. -- 不带CONCURRENTLY即为全量刷新,带CONCURRENTLY即为增量刷新
  25. -- 全量刷新速度较快,但是刷新时会阻塞对book_mv的查询,增量刷新相反
  26. -- 实际业务中选增量刷新,定时执行refresh即可
  27. refresh MATERIALIZED VIEW CONCURRENTLY PUBLIC.book_mv;
  28. SELECT *FROM PUBLIC.book_mv;
  29. -- 删除物化视图
  30. DROP MATERIALIZED VIEW PUBLIC.book_mv;

遗憾的是:gp不支持物化视图

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/601855
推荐阅读
相关标签
  

闽ICP备14008679号