citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.4k stars 662 forks source link

Insert queries on tables with foreign keys are not counted in citus_stat_tenants #6896

Open halilozanakgul opened 1 year ago

halilozanakgul commented 1 year ago
CREATE TABLE tbl (a INT UNIQUE);
CREATE TABLE tbl2 (a INT REFERENCES tbl(a));

SELECT create_distributed_table ('tbl', 'a');
SELECT create_distributed_table ('tbl2', 'a');

INSERT INTO tbl VALUES (1);
SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
tenant_attribute | query_count_in_this_period
------------------+----------------------------
1                |                          1
(1 row)

INSERT INTO tbl2 VALUES (1);
SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
tenant_attribute | query_count_in_this_period
------------------+----------------------------
1                |                          1
(1 row)
halilozanakgul commented 1 year ago

I think this happens because this query runs another query in the worker:

SELECT 1 FROM ONLY "public"."tbl_102009" x WHERE "a" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x

and I think this somehow deletes the tenant attribute, so the query is not counted.