Include update and delete queries

pull/6753/head
Halil Ozan Akgul 2023-03-14 15:52:36 +03:00
parent 2aa30dd303
commit 5e9e67e5bf
5 changed files with 54 additions and 38 deletions

View File

@ -1997,11 +1997,25 @@ GenerateSingleShardRouterTaskList(Job *job, List *relationShardList,
} }
else else
{ {
Datum partitionColumnValue;
Oid partitionColumnType = 0;
char *partitionColumnString = NULL;
if (job->partitionKeyValue != NULL)
{
partitionColumnValue = job->partitionKeyValue->constvalue;
partitionColumnType = job->partitionKeyValue->consttype;
partitionColumnString = DatumToString(partitionColumnValue,
partitionColumnType);
}
SetJobColocationId(job);
job->taskList = SingleShardTaskList(originalQuery, job->jobId, job->taskList = SingleShardTaskList(originalQuery, job->jobId,
relationShardList, placementList, relationShardList, placementList,
shardId, shardId,
job->parametersInJobQueryResolved, job->parametersInJobQueryResolved,
isLocalTableModification, "", -1); isLocalTableModification,
partitionColumnString, job->colocationId);
} }
} }

View File

@ -127,12 +127,12 @@ citus_stats_tenants(PG_FUNCTION_ARGS)
values[0] = Int32GetDatum(tenantStats->colocationGroupId); values[0] = Int32GetDatum(tenantStats->colocationGroupId);
values[1] = PointerGetDatum(cstring_to_text(tenantStats->tenantAttribute)); values[1] = PointerGetDatum(cstring_to_text(tenantStats->tenantAttribute));
values[2] = Int32GetDatum(tenantStats->selectsInThisPeriod); values[2] = Int32GetDatum(tenantStats->readsInThisPeriod);
values[3] = Int32GetDatum(tenantStats->selectsInLastPeriod); values[3] = Int32GetDatum(tenantStats->readsInLastPeriod);
values[4] = Int32GetDatum(tenantStats->selectsInThisPeriod + values[4] = Int32GetDatum(tenantStats->readsInThisPeriod +
tenantStats->insertsInThisPeriod); tenantStats->writesInThisPeriod);
values[5] = Int32GetDatum(tenantStats->selectsInLastPeriod + values[5] = Int32GetDatum(tenantStats->readsInLastPeriod +
tenantStats->insertsInLastPeriod); tenantStats->writesInLastPeriod);
values[6] = Int64GetDatum(tenantStats->score); values[6] = Int64GetDatum(tenantStats->score);
tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls); tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls);
@ -347,15 +347,17 @@ AttributeMetricsIfApplicable()
if (attributeCommandType == CMD_SELECT) if (attributeCommandType == CMD_SELECT)
{ {
tenantStats->selectCount++; tenantStats->readCount++;
tenantStats->selectsInThisPeriod++; tenantStats->readsInThisPeriod++;
tenantStats->totalSelectTime += cpu_time_used; tenantStats->totalReadTime += cpu_time_used;
} }
else if (attributeCommandType == CMD_INSERT) else if (attributeCommandType == CMD_UPDATE ||
attributeCommandType == CMD_INSERT ||
attributeCommandType == CMD_DELETE)
{ {
tenantStats->insertCount++; tenantStats->writeCount++;
tenantStats->insertsInThisPeriod++; tenantStats->writesInThisPeriod++;
tenantStats->totalInsertTime += cpu_time_used; tenantStats->totalWriteTime += cpu_time_used;
} }
LWLockRelease(&monitor->lock); LWLockRelease(&monitor->lock);
@ -376,10 +378,10 @@ AttributeMetricsIfApplicable()
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF) if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{ {
ereport(NOTICE, (errmsg("total select count = %d, total CPU time = %f " ereport(NOTICE, (errmsg("total read count = %d, total read CPU time = %f "
"to tenant: %s", "to tenant: %s",
tenantStats->selectCount, tenantStats->readCount,
tenantStats->totalSelectTime, tenantStats->totalReadTime,
tenantStats->tenantAttribute))); tenantStats->tenantAttribute)));
} }
} }
@ -405,13 +407,13 @@ UpdatePeriodsIfNecessary(MultiTenantMonitor *monitor, TenantStats *tenantStats)
* but there are some query count for this period we move them to the last period. * but there are some query count for this period we move them to the last period.
*/ */
if (tenantStats->lastQueryTime < monitor->periodStart && if (tenantStats->lastQueryTime < monitor->periodStart &&
(tenantStats->insertsInThisPeriod || tenantStats->selectsInThisPeriod)) (tenantStats->writesInThisPeriod || tenantStats->readsInThisPeriod))
{ {
tenantStats->insertsInLastPeriod = tenantStats->insertsInThisPeriod; tenantStats->writesInLastPeriod = tenantStats->writesInThisPeriod;
tenantStats->insertsInThisPeriod = 0; tenantStats->writesInThisPeriod = 0;
tenantStats->selectsInLastPeriod = tenantStats->selectsInThisPeriod; tenantStats->readsInLastPeriod = tenantStats->readsInThisPeriod;
tenantStats->selectsInThisPeriod = 0; tenantStats->readsInThisPeriod = 0;
} }
/* /*
@ -419,9 +421,9 @@ UpdatePeriodsIfNecessary(MultiTenantMonitor *monitor, TenantStats *tenantStats)
*/ */
if (tenantStats->lastQueryTime < monitor->periodStart - CitusStatsTenantsPeriod) if (tenantStats->lastQueryTime < monitor->periodStart - CitusStatsTenantsPeriod)
{ {
tenantStats->insertsInLastPeriod = 0; tenantStats->writesInLastPeriod = 0;
tenantStats->selectsInLastPeriod = 0; tenantStats->readsInLastPeriod = 0;
} }
} }

View File

@ -21,15 +21,15 @@ typedef struct TenantStats
int colocationGroupId; int colocationGroupId;
int selectCount; int readCount;
double totalSelectTime; double totalReadTime;
int selectsInLastPeriod; int readsInLastPeriod;
int selectsInThisPeriod; int readsInThisPeriod;
int insertCount; int writeCount;
double totalInsertTime; double totalWriteTime;
int insertsInLastPeriod; int writesInLastPeriod;
int insertsInThisPeriod; int writesInThisPeriod;
time_t lastQueryTime; time_t lastQueryTime;

View File

@ -44,9 +44,9 @@ SELECT create_reference_table('ref_tbl');
INSERT INTO dist_tbl VALUES (1, 'abcd'); INSERT INTO dist_tbl VALUES (1, 'abcd');
INSERT INTO dist_tbl VALUES (2, 'abcd'); INSERT INTO dist_tbl VALUES (2, 'abcd');
INSERT INTO dist_tbl VALUES (3, 'abcd'); UPDATE dist_tbl SET b = a + 1 WHERE a = 3;
INSERT INTO dist_tbl VALUES (4, 'abcd'); UPDATE dist_tbl SET b = a + 1 WHERE a = 4;
INSERT INTO dist_tbl VALUES (5, 'abcd'); DELETE FROM dist_tbl WHERE a = 5;
\c - - - :worker_1_port \c - - - :worker_1_port
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period

View File

@ -24,9 +24,9 @@ SELECT create_reference_table('ref_tbl');
INSERT INTO dist_tbl VALUES (1, 'abcd'); INSERT INTO dist_tbl VALUES (1, 'abcd');
INSERT INTO dist_tbl VALUES (2, 'abcd'); INSERT INTO dist_tbl VALUES (2, 'abcd');
INSERT INTO dist_tbl VALUES (3, 'abcd'); UPDATE dist_tbl SET b = a + 1 WHERE a = 3;
INSERT INTO dist_tbl VALUES (4, 'abcd'); UPDATE dist_tbl SET b = a + 1 WHERE a = 4;
INSERT INTO dist_tbl VALUES (5, 'abcd'); DELETE FROM dist_tbl WHERE a = 5;
\c - - - :worker_1_port \c - - - :worker_1_port
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute;