From d811a71da0db2389fac9ecd091c74c2894ea0597 Mon Sep 17 00:00:00 2001 From: Tyler Parsons Date: Wed, 24 Jan 2018 14:09:39 -0500 Subject: [PATCH 1/3] Fix incorrect timestamps in CDB_TableMetadata_Text Instead of performing a proper join on tabname, CDB_TableMetadata_Text joins cdb_tablemetadata against pg_catalog.pg_class (i.e. All postgres tables, views, indices, etc.) and gives a record for every possible tabname and updated_at combination. This results in the latest updated timestamp being chosen for any table in CDB_Get_Foreign_Updated_At, which leads to unnecessary and incorrect cache invalidation. --- scripts-available/CDB_TableMetadata.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-available/CDB_TableMetadata.sql b/scripts-available/CDB_TableMetadata.sql index bca7c47..ee63a00 100644 --- a/scripts-available/CDB_TableMetadata.sql +++ b/scripts-available/CDB_TableMetadata.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS CREATE OR REPLACE VIEW public.CDB_TableMetadata_Text AS SELECT FORMAT('%I.%I', n.nspname::text, c.relname::text) tabname, updated_at - FROM public.CDB_TableMetadata, pg_catalog.pg_class c + FROM public.CDB_TableMetadata m JOIN pg_catalog.pg_class c ON m.tabname::oid = c.oid LEFT JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid; -- No one can see this From acd101af9befc307b2872bf6fbc0f38a0a6264c5 Mon Sep 17 00:00:00 2001 From: Tyler Parsons Date: Tue, 23 Jan 2018 23:49:54 -0500 Subject: [PATCH 2/3] Use PGPORT as fdw port if specified --- test/extension/test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/extension/test.sh b/test/extension/test.sh index 4a1f122..a38bfac 100755 --- a/test/extension/test.sh +++ b/test/extension/test.sh @@ -513,7 +513,12 @@ END DATABASE=fdw_target sql postgres "SELECT cdb_tablemetadatatouch('test_fdw.foo'::regclass);" DATABASE=fdw_target sql postgres "SELECT cdb_tablemetadatatouch('test_fdw.foo2'::regclass);" - sql postgres "SELECT cartodb.CDB_Conf_SetConf('fdws', '{\"test_fdw\": {\"server\": {\"host\": \"localhost\", \"dbname\": \"fdw_target\"}, + # Add PGPORT to conf if it is set + PORT_SPEC="" + if [[ "$PGPORT" != "" ]] ; then + PORT_SPEC=", \"port\": \"$PGPORT\"" + fi + sql postgres "SELECT cartodb.CDB_Conf_SetConf('fdws', '{\"test_fdw\": {\"server\": {\"host\": \"localhost\", \"dbname\": \"fdw_target\" $PORT_SPEC }, \"users\": {\"public\": {\"user\": \"fdw_user\", \"password\": \"foobarino\"}}}}')" sql postgres "SELECT cartodb._CDB_Setup_FDW('test_fdw')" From 5c860290295567052f18ee479512c6dc38abef87 Mon Sep 17 00:00:00 2001 From: Tyler Parsons Date: Thu, 25 Jan 2018 22:55:41 -0500 Subject: [PATCH 3/3] Test for correct timestamps in cdb_tablemetadata_text --- test/extension/test.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/extension/test.sh b/test/extension/test.sh index a38bfac..d674e5f 100755 --- a/test/extension/test.sh +++ b/test/extension/test.sh @@ -388,6 +388,36 @@ function test_cdb_tablemetadatatouch_fully_qualifies_names() { sql postgres 'DROP TABLE touch_invalidations' } +function test_cdb_tablemetadata_text() { + + #create and touch tables + sql "CREATE TABLE touch_ex_a (id int);" + sql "CREATE TABLE touch_ex_b (id int);" + sql "CREATE TABLE touch_ex_c (id int);" + sql postgres "SELECT CDB_TableMetadataTouch('touch_ex_a');" + sql postgres "SELECT CDB_TableMetadataTouch('touch_ex_b');" + sql postgres "SELECT CDB_TableMetadataTouch('touch_ex_c');" + + #ensure there is 1 record per table + QUERY="SELECT COUNT(1) FROM (SELECT 1 FROM cdb_tablemetadata_text " + QUERY+="GROUP BY tabname HAVING COUNT(1) > 1) s;" + sql postgres "$QUERY" should "0" + + #ensure timestamps are distinct and properly ordered + QUERY="SELECT (SELECT updated_at FROM CDB_TableMetadata_Text WHERE tabname='public.touch_ex_a')" + QUERY+=" < (SELECT updated_at FROM CDB_TableMetadata_Text WHERE tabname='public.touch_ex_b');" + sql postgres "$QUERY" should "t" + QUERY="SELECT (SELECT updated_at FROM CDB_TableMetadata_Text WHERE tabname='public.touch_ex_b')" + QUERY+=" < (SELECT updated_at FROM CDB_TableMetadata_Text WHERE tabname='public.touch_ex_c');" + sql postgres "$QUERY" should "t" + + #cleanup + sql "DROP TABLE touch_ex_a;" + sql "DROP TABLE touch_ex_b;" + sql "DROP TABLE touch_ex_c;" + +} + function test_cdb_column_names() { sql cdb_testmember_1 'CREATE TABLE cdb_testmember_1.table_cnames(c int, a int, r int, t int, o int);' sql cdb_testmember_2 'CREATE TABLE cdb_testmember_2.table_cnames(d int, b int);'