Scheduling Estimates Computations
Explore how to estimate unique visitor counts efficiently in PostgreSQL by using HyperLogLog with stored procedures. Learn to create scheduled background processes and interactive queries that update visitor estimates while avoiding double counting by combining data sets.
We'll cover the following...
To calculate unique visitor estimates from the heavy insert table, we need a background process to do this from time to time.
The easiest way to do that here would be to create a new API endpoint on our back-end server and set up a cron-like utility to use that endpoint for our specified schedule. In case of emergency, though, it’s nice to be able to run this updating process interactively. A solution to have both the back-end API integration and the interactive approaches available consist of packaging our SQL query as a stored procedure.
SQL function
While stored procedures aren’t covered, it’s easy enough to write a SQL function around the statement we have already:
And here’s an interactive session where we use the newly defined stored procedure to update our unique visitors hll table. ...