From ebbcc5aee28543369d39e0164ce21283f0d5f112 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 11 Jul 2024 13:50:42 +0300 Subject: [PATCH] Add COPY command support, thanks for Andrew Bille for test patch --- expected/online_analyze.out | 25 +++++++++++++++++++++++++ online_analyze.c | 5 +++++ sql/online_analyze.sql | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/expected/online_analyze.out b/expected/online_analyze.out index ddc7bcb..a47858f 100644 --- a/expected/online_analyze.out +++ b/expected/online_analyze.out @@ -44,4 +44,29 @@ SHOW online_analyze.exclude_tables; (1 row) +SET "online_analyze.verbose" = off; +CREATE TABLE insert_tbl( + foo int, + bar text +); +CREATE TABLE copy_tbl( + foo int, + bar text +); +INSERT INTO insert_tbl VALUES (1,'a'); +COPY copy_tbl (foo, bar) FROM stdin; +SELECT * FROM copy_tbl; + foo | bar +-----+----- + 1 | a +(1 row) + +-- Both must be true +SELECT last_analyze IS NOT NULL AS analyzed, relname FROM pg_stat_user_tables ORDER BY relname; + analyzed | relname +----------+------------ + t | copy_tbl + t | insert_tbl +(2 rows) + SET online_analyze.enable = off; diff --git a/online_analyze.c b/online_analyze.c index 0021fc3..b9aae90 100644 --- a/online_analyze.c +++ b/online_analyze.c @@ -1048,6 +1048,11 @@ onlineAnalyzeHookerUtility( } else tblnames = NIL; + } else if (IsA(parsetree, CopyStmt)) { + CopyStmt *cpystmt = (CopyStmt*) parsetree; + + tblnames = list_make1((RangeVar*)copyObject(cpystmt->relation)); + op = CK_CREATE; } } diff --git a/sql/online_analyze.sql b/sql/online_analyze.sql index 760eaca..0ef8f86 100644 --- a/sql/online_analyze.sql +++ b/sql/online_analyze.sql @@ -18,4 +18,22 @@ SHOW online_analyze.exclude_tables; DROP TABLE oa_tbl; SHOW online_analyze.exclude_tables; +SET "online_analyze.verbose" = off; + +CREATE TABLE insert_tbl( + foo int, + bar text +); +CREATE TABLE copy_tbl( + foo int, + bar text +); +INSERT INTO insert_tbl VALUES (1,'a'); +COPY copy_tbl (foo, bar) FROM stdin; +1 a +\. +SELECT * FROM copy_tbl; +-- Both must be true +SELECT last_analyze IS NOT NULL AS analyzed, relname FROM pg_stat_user_tables ORDER BY relname; + SET online_analyze.enable = off; -- 2.46.1