Automatic Index Recommendations using pg_qualstats and HypoPG — HypoPG is a Postgres extension for creating ‘hypothetical indexes’, essentially virtual indexes you can use to test if a certain index would improve your queries ahead of time. This article takes things to the next step by automatically trying to find indexes worth creating.
Avinash Vallarapu
|
Chef’s CTO Chooses StrongDM — Adam Jacob says “strongDM takes the friction out of getting end users access to the systems they need.” Zero trust access to any database, server or k8 cluster. Click here to try for free.
strongDM
|
Don’t Forget the Benefits of BRIN Indexes — BRIN indexes (which provide an efficient way to index values that can be grouped into ‘ranges’) were introduced in Postgres 9.5 and have some specific use cases. This post benchmarks a situation where they can really help.
Jobin Augustine
|
supported by
💡 Tip of the Week
Using ROLLUP to get an overall results row for aggregations
If you want to group and aggregate results together, using GROUP BY with a single column is a common approach, but ROLLUP is one of a handful of clauses that can help you take things to another dimension by letting you group by multiple sets in a single query.
This is a feature best demonstrated live, so let's create a table and load in some sample data.. the number of goals scored by different soccer teams in different years:
|
CREATE TABLE goals (
team TEXT, year INT, goals INT);
INSERT INTO goals VALUES
('USA', 2010, 5), ('USA', 2011, 3),
('USA', 2012, 12), ('ENG', 2010, 17),
('ENG', 2011, 9), ('ENG', 2012, 11);
|
If we wanted to get the average number of goals scored per year, per team, we could do this:
|
SELECT team, ROUND(AVG(goals))
FROM goals GROUP BY team;
|
But let's say we wanted to not only group by teams but also by the overall table (i.e. no column) to get the number of average goals overall. We could do this:
|
SELECT team, ROUND(AVG(goals))
FROM goals GROUP BY ROLLUP(team);
|
This gets us a result like so: |
team | round
---------------
ENG | 12
USA | 7
(null)| 10
|
There's a lot more to this than we can cover here, so enjoy this tutorial to learn more.
This week's tip is brought to you by Gremlin, a platform that helps you build more resilient software through running thoughtful Chaos Engineering experiments. Learn more at gremlin.com.
|
|
🗓 Upcoming Postgres Events
|
|
|