Loading video...

Video Failed to Load

Go Home

Database table size impacts performance in more ways than one: a) B-tree depth. Using 8k pages and a 16b uuid: 1 level = ~370 rows 2 levels = ~138k rows 3 levels = ~50m rows 4 levels = ~20b rows The lookup cost on a table with 100k rows...

212,291 views • 4 months ago •via X (Twitter)

0 Comments

No comments available

Comments from the original post will appear here

Related Videos

SQL has levels to it: - level 1 SELECT, FROM, WHERE, GROUP BY, HAVING, LIMIT Master these basic keywords and you’ll be well on your way to mastering SQL. - level 2 Mastering JOINs: Most common JOINs: INNER and LEFT Less common JOINs: FULL OUTER Joins you should avoid almost always: RIGHT and CROSS JOIN Mastering common table expressions (CTEs). The WITH keyword defines a CTE which you can imagine as a “variable” that you can query later. Using variables like this you can master algorithm techniques like recursion, breadth first search and more! CTEs also make your SQL much more readable and make your coworkers hate you less compared to nested sub queries. - level 3 Mastering window functions Window functions have 3 pieces: The function (i.e. SUM, RANK, AVG) The over clause to start the window The window definition which has 3 pieces: - how to split the window up with PARTITION BY - how to order the window with ORDER BY - how to restrict the window size with ROWS clause (useful for rolling monthly averages) Understand RANK vs DENSE_RANK vs ROW_NUMBER, I have been asked this in interviews a million times. - level 4 You understand table scans, b-tree indexes, and partitioning schemes to increase performance. Doing something like COUNT(CASE WHEN) is much better than doing multiple queries with a UNION ALL. UNION ALL is terrible for all sorts of reasons that I don’t want to get into in this post. B-trees indexes allow for efficient scanning of data in the WHERE clause. Use explain plans to understand if an index is actually being used or not! Partitioning is similar to indexes except it’s a “poor mans” index. It just keeps data in specific folders and skips the folders that don’t include the data I question. What else did I miss for mastering SQL?

Zach Wilson

34,452 views • 3 months ago

SQL has levels to it: - level 1 SELECT, FROM, WHERE, GROUP BY, HAVING, LIMIT Master these basic keywords and you’ll be well on your way to mastering SQL. - level 2 Mastering JOINs: Most common JOINs: INNER and LEFT Less common JOINs: FULL OUTER Joins you should avoid almost always: RIGHT and CROSS JOIN Mastering common table expressions (CTEs). The WITH keyword defines a CTE which you can imagine as a “variable” that you can query later. Using variables like this you can master algorithm techniques like recursion, breadth first search and more! CTEs also make your SQL much more readable and make your coworkers hate you less compared to nested sub queries. - level 3 Mastering window functions Window functions have 3 pieces: The function (i.e. SUM, RANK, AVG) The over clause to start the window The window definition which has 3 pieces: - how to split the window up with PARTITION BY - how to order the window with ORDER BY - how to restrict the window size with ROWS clause (useful for rolling monthly averages) Understand RANK vs DENSE_RANK vs ROW_NUMBER, I have been asked this in interviews a million times. - level 4 You understand table scans, b-tree indexes, and partitioning schemes to increase performance. Doing something like COUNT(CASE WHEN) is much better than doing multiple queries with a UNION ALL. UNION ALL is terrible for all sorts of reasons that I don’t want to get into in this post. B-trees indexes allow for efficient scanning of data in the WHERE clause. Use explain plans to understand if an index is actually being used or not! Partitioning is similar to indexes except it’s a “poor mans” index. It just keeps data in specific folders and skips the folders that don’t include the data I question. What else did I miss for mastering SQL?

Zach Wilson

79,681 views • 1 year ago

Gilbert Strang, the legendary mathematician who taught linear algebra for 61 years and became the most watched math professor in history: "I used to think a matrix was just a grid of numbers, until I proved that its rows and columns always agree on one number no matter how you look at them. That fact still feels like magic to me after sixty years." this is the exact proof sitting quietly underneath every factor model a risk desk trusts with real capital, and almost nobody outside a math department has ever seen it. strip away the notation and the idea is almost absurdly simple. take any matrix, any grid of numbers, and count how many of its rows are truly independent, meaning none of them can be built out of the others. now count the independent columns instead, a completely different question on the surface. those two numbers, row independence and column independence, always turn out exactly equal, no matter how large or lopsided the matrix is. nobody presenting a clean risk model out loud credits a decades old proof for the reason the math even holds together. zoom out to what this means for anything built on a grid of numbers today. a portfolio, a covariance matrix, a neural network's weights, all of them hide a true dimension smaller than their size suggests, and that hidden number is exactly what this proof pins down. the industry sells complexity as scale, more assets, more parameters, more rows and columns. but the real question was never how big the matrix is. it's how many independent directions are actually hiding inside it. the size of the grid was never the real story. it was the one number both sides of it were quietly agreeing on the whole time.

MindArch

18,494 views • 1 month ago

February 1971. State House Entebbe. On the gardens before the grand residence, party was underway. Former monarchs and royal representatives, from Buganda, Toro, Ankole, Bunyoro, sat in rows of chairs. Before them, a table draped in white cloth. Behind it sat Idi Amin, an army officer, and a few white dignitaries. The press stood to the side. Traditional dancers moved in front. The scene was carefully arranged. Amin, chest out, swaggering with the confidence of a man recently crowned by force, sat behind the table with the microphone. Beside him, an army officer and a handful of white dignitaries, lingering evidence of the old colonial networks that still hovered around Uganda's new power. The table was draped in white cloth, and the microphone stood at its centre, waiting to carry his words to the nation beyond the gates. On either side of the table, in neat rows of chairs, sat the remnants of Uganda's ancient dynasties. From Buganda came Prince Badru Kakungulu, Prince Mawanda, and Princess Mazzi, along with Nnabagereka of Buganda, widow of the exiled Kabaka. From Toro came the aged former Omukama, and from Ankole and Bunyoro came their own representatives, princes and elders who had once presided over proud kingdoms. They had come hoping for something. Perhaps restoration. Perhaps recognition. Perhaps simply the assurance that their place in Uganda's story had not been erased entirely. In front of the seated dignitaries, traditional dancers from various regions twirled and stamped, their drums beating out rhythms that predated the colonial era itself. The press stood to the side, cameras clicking, recording every moment for the world outside. It was a spectacle designed to project unity, a gathering of cultures, a celebration of heritage. Then Captain Ochima rose and read the soldiers' declaration. Then Amin himself leaned into the microphone. The message was swift and absolute. Uganda would remain a Republic. The kingdoms would not return. In one gesture, he dismissed both the colonial constitutional compromises and Obote's revolutionary centralism. As he would later declare, "there can be no return of feudal kings or kingdoms, because Uganda is going forward, not backward." The royal representatives listened in silence. They had been honoured, but not restored. Amin had called them to Entebbe not to return their crowns, but to remind them, and the nation, that only one seat of power remained. The message had been delivered. #ughistory Government of Uganda #IdiAmin

UgHistory

35,040 views • 22 days ago

Big moment for Postgres! AI coding tools have been surprisingly bad at writing Postgres code. Not because the models are dumb, but because of how they learned SQL in the first place. LLMs are trained on the internet, which is full of outdated Stack Overflow answers and quick-fix tutorials. So when you ask an AI to generate a schema, it gives you something that technically runs but misses decades of Postgres evolution, like: - No GENERATED ALWAYS AS IDENTITY (added in PG10) - No expression or partial indexes - No NULLS NOT DISTINCT (PG15) - Missing CHECK constraints and proper foreign keys - Generic naming that tells you nothing But this is actually a solvable problem. You can teach AI tools to write better Postgres by giving them access to the right documentation at inference time. This exact solution is actually implemented in the newly released pg-aiguide by Tiger Data - Creators of TimescaleDB, which is an open-source MCP server that provides coding tools access to 35 years of Postgres expertise. In a gist, the MCP server enables: - Semantic search over the official PostgreSQL manual (version-aware, so it knows PG14 vs PG17 differences) - Curated skills with opinionated best practices for schema design, indexing, and constraints. I ran an experiment with Claude Code to see how well this works, and worked with the team to put this together. Prompt: "Generate a schema for an e-commerce site twice, one with the MCP server disabled, one with it enabled. Finally, run an assessment to compare the generated schemas." The run with the MCP server led to: - 420% more indexes (including partial and expression indexes) - 235% more constraints - 60% more tables (proper normalization) - 11 automation functions and triggers - Modern PG17 patterns throughout The MCP-assisted schema had proper data integrity, performance optimizations baked in, and followed naming conventions that actually make sense in production. pg-aiguide works with Claude Code, Cursor, VS Code, and any MCP-compatible tool. It's free and fully open source. I have shared the repo in the replies!

Avi Chawla

187,076 views • 8 months ago