Commit e5d7be09 authored by Meet Narendra's avatar Meet Narendra 💬

YOLO

parent 07afc8d8
# CS631-Project # CS631-Project: Automatic Index creation in postgres.
***Authors** @meet.doshi @gaurangathavale @jiteshg*
---
#### For checking patch updates
```
Just look at the following files
execMain.c
nodeSeqScan.c
worker_spi/worker_spi.c
Makefile
Look for following tags
/* CS631 start */
/* CS631 end */
```
###File Structure:
```
<22m0742_22m0752>
├── execMain.c ~ User queries without where clause dont reach node sequential scan level. So they have to be stored at execMain level. Currently we are only saving insert and delete queries.
├── nodeSeqScan.c ~ Operates at table level. Here we are keeping track of all select queries with and without where clause.
├── worker_spi/ ~ This module should be registered in contrib folder and requires updates in the make file in same folder.
│ ├── worker_spi.c ~ This is the daemon process which runs every 20 seconds. It alternates with a toggle where first time it fetches info and decides which index to create. On the next round it executes the query and creates the index.
└── readme.md
```
###Tasks:
1. Storing logs of incoming user queries for later use on making a decision whether to create an index or not.
2. Creating a daemon process like a cron job for the database which runs regularly to check whether indexes need to be created or not.
3. Building up logic for the daemon process to decided whether indexes need to be created or deleted.
###Cautions:
1. Installing worker module correctly and updating makefiles.
2. Accessing uninitialized or modifying static memory.
3. Recursive loops inside code.
4. Codebase changes due to changes in postgres versions. So be sure to check if the data structures and libraries are matching.
5. Mutliple where clauses and subqueries.
6. Current postgres version 13.7 `Different from the git version`
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
# Generated subdirectories
/log/
/results/
/tmp_check/
# src/test/modules/worker_spi/Makefile
MODULES = worker_spi
EXTENSION = worker_spi
DATA = worker_spi--1.0.sql
PGFILEDESC = "worker_spi - background worker example"
REGRESS = worker_spi
# enable our module in shared_preload_libraries for dynamic bgworkers
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/worker_spi/dynamic.conf
# Disable installcheck to ensure we cover dynamic bgworkers.
NO_INSTALLCHECK = 1
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/worker_spi
top_builddir = ../../
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
shared_preload_libraries = worker_spi
worker_spi.database = contrib_regression
CREATE EXTENSION worker_spi;
SELECT worker_spi_launch(4) IS NOT NULL;
?column?
----------
t
(1 row)
-- wait until the worker completes its initialization
DO $$
DECLARE
visible bool;
loops int := 0;
BEGIN
LOOP
visible := table_name IS NOT NULL
FROM information_schema.tables
WHERE table_schema = 'schema4' AND table_name = 'counted';
IF visible OR loops > 120 * 10 THEN EXIT; END IF;
PERFORM pg_sleep(0.1);
loops := loops + 1;
END LOOP;
END
$$;
INSERT INTO schema4.counted VALUES ('total', 0), ('delta', 1);
SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
-- wait until the worker has processed the tuple we just inserted
DO $$
DECLARE
count int;
loops int := 0;
BEGIN
LOOP
count := count(*) FROM schema4.counted WHERE type = 'delta';
IF count = 0 OR loops > 120 * 10 THEN EXIT; END IF;
PERFORM pg_sleep(0.1);
loops := loops + 1;
END LOOP;
END
$$;
SELECT * FROM schema4.counted;
type | value
-------+-------
total | 1
(1 row)
CREATE EXTENSION worker_spi;
SELECT worker_spi_launch(4) IS NOT NULL;
-- wait until the worker completes its initialization
DO $$
DECLARE
visible bool;
loops int := 0;
BEGIN
LOOP
visible := table_name IS NOT NULL
FROM information_schema.tables
WHERE table_schema = 'schema4' AND table_name = 'counted';
IF visible OR loops > 120 * 10 THEN EXIT; END IF;
PERFORM pg_sleep(0.1);
loops := loops + 1;
END LOOP;
END
$$;
INSERT INTO schema4.counted VALUES ('total', 0), ('delta', 1);
SELECT pg_reload_conf();
-- wait until the worker has processed the tuple we just inserted
DO $$
DECLARE
count int;
loops int := 0;
BEGIN
LOOP
count := count(*) FROM schema4.counted WHERE type = 'delta';
IF count = 0 OR loops > 120 * 10 THEN EXIT; END IF;
PERFORM pg_sleep(0.1);
loops := loops + 1;
END LOOP;
END
$$;
SELECT * FROM schema4.counted;
/* src/test/modules/worker_spi/worker_spi--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION worker_spi" to load this file. \quit
CREATE FUNCTION worker_spi_launch(pg_catalog.int4)
RETURNS pg_catalog.int4 STRICT
AS 'MODULE_PATHNAME'
LANGUAGE C;
This diff is collapsed.
# worker_spi extension
comment = 'Sample background worker'
default_version = '1.0'
module_pathname = '$libdir/worker_spi'
relocatable = true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment