-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 40e55fd
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- Drop existing tables if they exist | ||
DROP MATERIALIZED VIEW IF EXISTS mv_normal; | ||
DROP TABLE IF EXISTS pgbench_accounts; | ||
DROP TABLE IF EXISTS pgbench_branches; | ||
|
||
-- Create sample tables | ||
CREATE TABLE pgbench_accounts ( | ||
aid INT PRIMARY KEY, | ||
abalance INT, | ||
bid INT -- Ensure this column exists for the join | ||
); | ||
|
||
CREATE TABLE pgbench_branches ( | ||
bid INT PRIMARY KEY, | ||
bbalance INT | ||
); | ||
|
||
-- Insert some sample data | ||
INSERT INTO pgbench_accounts (aid, abalance, bid) VALUES (1, 1000, 1), (2, 2000, 2); | ||
INSERT INTO pgbench_branches (bid, bbalance) VALUES (1, 500), (2, 600); | ||
|
||
|
||
-- Create a normal materialized view | ||
CREATE MATERIALIZED VIEW mv_normal AS | ||
SELECT a.aid, b.bid, a.abalance, b.bbalance | ||
FROM pgbench_accounts a | ||
JOIN pgbench_branches b ON a.bid = b.bid; -- Use explicit join condition | ||
|
||
-- Test REFRESH MATERIALIZED VIEW | ||
REFRESH MATERIALIZED VIEW mv_normal; | ||
|
||
|
||
-- Create the pg_ivm extension | ||
CREATE EXTENSION pg_ivm; | ||
|
||
-- Create an IMMV | ||
SELECT create_immv('immv', 'SELECT a.aid, b.bid, a.abalance, b.bbalance FROM pgbench_accounts a JOIN pgbench_branches b ON a.bid = b.bid'); | ||
|
||
-- Test updating base tables and IMMV | ||
UPDATE pgbench_accounts SET abalance = 1234 WHERE aid = 1; | ||
SELECT * FROM immv WHERE aid = 1; | ||
|
||
-- Drop index for further testing | ||
DROP INDEX IF EXISTS immv_index; | ||
|
||
-- Update base tables and test performance without index | ||
UPDATE pgbench_accounts SET abalance = 9876 WHERE aid = 1; | ||
SELECT * FROM immv WHERE aid = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM ghcr.io/cloudnative-pg/postgresql:16-bookworm | ||
|
||
# Set environment variables for PostgreSQL | ||
ENV POSTGRES_USER=postgres | ||
ENV POSTGRES_PASSWORD=postgres | ||
ENV POSTGRES_DB=postgres | ||
|
||
USER root | ||
|
||
# Install build dependencies and pg_cron | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
build-essential \ | ||
git \ | ||
postgresql-server-dev-16 \ | ||
postgresql-16-cron | ||
|
||
# Configure PostgreSQL for pg_cron | ||
RUN echo "shared_preload_libraries = 'pg_cron'" >> /usr/share/postgresql/postgresql.conf.sample && \ | ||
echo "cron.database_name = 'postgres'" >> /usr/share/postgresql/postgresql.conf.sample && \ | ||
echo "cron.timezone = 'GMT'" >> /usr/share/postgresql/postgresql.conf.sample | ||
|
||
# Clone the pg_ivm repository | ||
RUN git clone https://github.com/sraoss/pg_ivm.git /pg_ivm | ||
|
||
# Build and install the pg_ivm extension | ||
WORKDIR /pg_ivm | ||
RUN make && make install | ||
|
||
# Switch back to the default directory | ||
WORKDIR / | ||
|
||
USER 26 | ||
|
||
# Expose the PostgreSQL port | ||
EXPOSE 5432 | ||
|
||
# Start PostgreSQL server | ||
CMD ["postgres"] |