Skip to main content

Getting usage of tables in queries

  • July 2, 2019
  • 2 replies
  • 6 views

savyuk
Hi,
A customer wants to get statistics for table usage in queries. How many times tables were read from by selects.
How can we do something like this without parsing the SQL from query_requests?

Regards, Pavel
Sent from mobile, apologies for brevity/typos

2 replies

MaciejPaliwoda
Forum|alt.badge.img+2
  • Participating Frequently
  • July 2, 2019
Vbudy script has sth like this..just run rhe report once and you will see the query (section Most Frequently used tables - if i remember correctly)

Vertica_Curtis
Forum|alt.badge.img+1
  • Participating Frequently
  • July 2, 2019

projection_usage would show you projections used, and you could easily infer what table that was from the projection name.

But the better way, IMHO, is to retain query_requests, or query_profiles, because generally these tables only have a few days' or weeks worth of data in them. You can increase the retention on these tables, but it's better to just run a cron process to just copy the data from these tables into a permanent table that you can manage yourself.

Then slap a text index on the query field. Then you can run queries like how many times a given table was referenced in a query, or when the last time a table was used, etc. And because of the text index, you're not parsing a giant query string. The text index will make it a sub-second query, versus one that might take about 10-20 seconds otherwise. Powerful stuff.

BTW, that'll need to be a table you own (not query_profiles) because a text index requires a unique primary key, and you can't create that on query_profiles.