Skip to content

Commit

Permalink
Speed up get_top_operations_for_types query (#6041)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Nov 27, 2024
1 parent 6b97b97 commit 67c756c
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1295,10 +1295,6 @@ export class OperationsReader {
}>
>
> {
const ORs = args.typeNames.map(
typeName => sql`( cdi.coordinate = ${typeName} OR cdi.coordinate LIKE ${typeName + '.%'} )`,
);

const result = await this.clickHouse.query<{
total: string;
hash: string;
Expand All @@ -1319,7 +1315,10 @@ export class OperationsReader {
${this.createFilter({
target: args.targetId,
period: args.period,
extra: [sql`cdi.coordinate NOT LIKE '%.%.%'`, sql`(${sql.join(ORs, ' OR ')})`],
extra: [
sql`cdi.coordinate NOT LIKE '%.%.%'`,
sql`substringIndex(cdi.coordinate, '.', 1) IN (${sql.array(args.typeNames, 'String')})`,
],
namespace: 'cdi',
})}
GROUP BY cdi.hash, cdi.coordinate ORDER by total DESC, cdi.hash ASC LIMIT ${sql.raw(
Expand Down

0 comments on commit 67c756c

Please sign in to comment.