GithubHelp home page GithubHelp logo

pouyapouryaie / materializedview Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 59 KB

this sample, show how we can use materialized view in spring-framework

Java 100.00%
materializedview spring-boot postgresql datageneration

materializedview's Introduction

materializedView

  1. in order to generate data for test, go to the application.properties and add app.generator.enabled=true after that app.generator.enabled=false
  2. create tables and MATERIALIZED view
  3. populated materialized view
  4. create procedure for update view
  5. time of update config in materializedViewRefresher.class

drop table if exists

drop table if EXISTS product CASCADE;
drop table if EXISTS users CASCADE;
drop table if EXISTS purchase_order CASCADE;

create data base:

CREATE TABLE users(
    id serial PRIMARY KEY,
    firstname VARCHAR (50),
    lastname VARCHAR (50),
    state VARCHAR(10)
 );
 
 CREATE TABLE product(
    id serial PRIMARY KEY,
    description VARCHAR (500),
    price numeric (10,2) NOT NULL
 );
 
 CREATE TABLE purchase_order(
     id serial PRIMARY KEY,
     user_id integer references users (id),
     product_id integer references product (id)
 );

create view :

create view purchase_order_summary
as
select u.state,
       sum(p.price) as total_sale
from users u,
     product p,
     purchase_order po
where u.id = po.user_id
  and p.id = po.product_id
group by u.state
order by u.state

create materializedView

CREATE MATERIALIZED VIEW purchase_order_summary
AS
select 
    u.state,
    sum(p.price) as total_sale
from 
    users u,
    product p,
    purchase_order po
where 
    u.id = po.user_id
    and p.id = po.product_id
group by u.state
order by u.state
WITH NO DATA;
CREATE UNIQUE INDEX state_category ON purchase_order_summary (state);

-- first population:
REFRESH MATERIALIZED VIEW purchase_order_summary;

create procedure:

-- create procedure
CREATE OR REPLACE PROCEDURE refresh_mat_view()
LANGUAGE plpgsql    
AS $$
BEGIN
  REFRESH MATERIALIZED VIEW CONCURRENTLY purchase_order_summary;
END;
$$;

materializedview's People

Contributors

pouyapouryaie avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.