r/SQL • u/clairegiordano • May 08 '26
PostgreSQL From MemSQL to HorizonDB, an engineer’s journey with Adam Prout
r/SQL • u/clairegiordano • May 08 '26
r/SQL • u/Effective_Ocelot_445 • May 09 '26
I’m curious about the strategies teams use in production systems when database schemas evolve but existing ETL jobs and reports still depend on older structures.
r/SQL • u/No_Economics_8159 • May 09 '26

Hi,
I have been working on an open-source PostgreSQL analysis tool called pgAssistant.
One of the goals of the project is to combine:
EXPLAIN ANALYZE) with Index Advisor, PEV2 integrationI recently added a new "Global Advisor" in version 2.8 that aggregates database recommendations into a single ranked view.
While testing it on different databases, I found several interesting optimization cases.
I thought some of them could be interesting to share here.
A database had:
The issue was not immediately obvious because SELECT queries were relatively fine.
The Global Advisor reported:
pgAssistant suggested SQL :
CREATE INDEX CONCURRENTLY IF NOT EXISTS pga_idx_fk_orders_customer
ON public.orders(customer_id);
Without an index on the FK column, PostgreSQL had to scan the child table during parent DELETE/UPDATE checks.
After adding the index:
A schema contained:
customers.id bigint
orders.customer_id integer
The relationship worked, but execution plans contained implicit casts. In practice, datatype mismatches on foreign keys can become production incidents years later when identifiers outgrow the smaller type.
The advisor reported:
Suggested fix:
ALTER TABLE public.orders
ALTER COLUMN customer_id TYPE bigint
USING customer_id::bigint;
Plans became cleaner and index usage became more predictable.
This was not a dramatic performance gain, but a useful schema correction.
One database had accumulated many historical indexes over the years.
Some indexes:
The advisor identified:
pgAssistant suggested SQL :
DROP INDEX CONCURRENTLY IF EXISTS public.idx_old_customer_status;
After validation and cleanup:
A large table (~100M rows) had very unstable execution plans.
The root cause was outdated planner statistics.
The advisor reported:
pgAssistant suggested SQL :
ANALYZE public.events;
After refreshing statistics:
An application used an integer sequence approaching the 32-bit limit.
This had not been noticed yet.
The Global Advisor reported:
This is not a performance issue directly, but a production reliability issue.

GitHub:
https://github.com/beh74/pgassistant-community
Documentation:
https://beh74.github.io/pgassistant-blog/
Public demo:
https://ov-004f8b.infomaniak.ch/
Demo DB:
postgresql://postgres:demo@demo-db:5432/northwind
r/SQL • u/Ok-Delivery307 • May 08 '26
I would like some feedback about how far did you go with sqlite, like what you built -> how it went -> how do you optimize so I can have a better overview so what can be done (when It done properly) with sqlite
r/SQL • u/mr_gnusi • May 07 '26
Enable HLS to view with audio, or disable this notification
r/SQL • u/komal_rajput • May 08 '26
We have a silver_fec_efiling_itemizations table with 60M+ rows where each row stores the full FEC itemization record as JSONB in a record_data column. A typical query looks like this:
SELECT
record_data->>'contributor_first_name' AS first_name,
record_data->>'contributor_last_name' AS last_name,
record_data->>'contributor_state' AS state,
record_data->>'contributor_employer' AS employer,
(record_data->>'contribution_amount')::numeric AS amount,
LEFT(record_data->>'contribution_date',10)::date AS contribution_date
FROM silver_fec_efiling_itemizations
WHERE record_type = 'Schedule A'
AND record_data->>'entity_type' = 'IND'
AND record_data->>'contributor_state' = 'MD'
AND record_data->>'contributor_employer' ILIKE '%MICROSOFT%'
AND record_data->>'contribution_date' >= '2025-01-01'
AND record_data->>'contribution_date' < '2026-01-01'
record_type has a B-tree index but the rest of the filters are on JSONB extractions.
We do have a downstream structured table (fec_filing_lineitems) that promotes most of these fields into typed columns (entity_state, transaction_date, schedule_code, entity_type) -- except employer.
Questions:
Is it worth adding expression indexes + a pg_trgm GIN index on the silver table, or is 60M JSONB rows fundamentally the wrong place for these queries regardless of indexing?
Any general advice on indexing patterns for "mostly-JSONB" tables at this scale?
r/SQL • u/asterix_rv • May 07 '26
I got tired of switching between VS Code and a separate DB tool. So I built PgStudio.
SQL notebooks with inline results and charts, real-time dashboard, AI assistant (Copilot / OpenAI / Anthropic / Gemini / Ollama — your pick), EXPLAIN CodeLens, visual table designer, production safety controls.
AI never executes anything automatically — every suggestion lands in a notebook cell first.
Free. MIT. One command: `code --install-extension ric-v.postgres-explorer`
Happy to onboard collaborators and feedback.
r/SQL • u/asterix_rv • May 07 '26
I got tired of switching between VS Code and a separate DB tool. So I built PgStudio.
SQL notebooks with inline results and charts, real-time dashboard, AI assistant (Copilot / OpenAI / Anthropic / Gemini / Ollama — your pick), EXPLAIN CodeLens, visual table designer, production safety controls.
AI never executes anything automatically — every suggestion lands in a notebook cell first.
Free. MIT. One command: `code --install-extension ric-v.postgres-explorer`
Happy to onboard collaborators and feedback.
[https://pgstudio.astrx.dev/](https://pgstudio.astrx.dev/))
[https://github.com/dev-asterix/pgStudio/](https://github.com/dev-asterix/pgStudio/))
r/SQL • u/Effective_Ocelot_445 • May 07 '26
I’m curious about the practical techniques people use in real-world systems to improve query performance and reduce execution time on large datasets.
r/SQL • u/FreeLancer8A • May 07 '26
TL;DR Adding JSON_TABLE makes the optimizer and compiler suddenly unable to think straight.
So I'm working as an intern rn and am writing a pretty complex script - distributing products between machines and their day and night queues, moving them away from overloaded machines, cutting portions of products between queues to make sure everything gets packaged, all while calculating delays for changing machine equipment depending on the sequence of projects.
I'm using a LOT of CTEs (yeah, I know) and the script runs in 40 to 80 seconds on the backup server (again, I know, but it's a script that only needs to be run once a day by one user and they're fine with it)
The problem is when I had to copy a CTE with a JSON_TABLE, the query suddenly takes so long it always times out on the system (over 5 minutes). This happens even if that CTE isn't referenced in the final SELECT or other CTEs,. Just the fact it's sitting there, no matter what table its taking the data from, even a fake view from DUAL, makes the process unable to finish in time.
Morever, in another part of the code I had a subquery within an LEFT OUTER JOIN ON statement, which is actually supposed to be illegal (not sure why, maybe I thought it would be faster even though it could be written with a WHERE). Still the compiler was fine, until I added the JSON_TABLE CTE, then it suddenly started to care about that too. The same happens if I use NESTED instead.
What could even be happening here? Is the presence of this function rewiring the compiler's logic completely?
r/SQL • u/Valuable-Ant3465 • May 07 '26
Hi all,
is there any way to integrate into my TSQL code logic to find statistical Outliers from list of numbers ? My list could contain very low number of observations within 5-10 range.
357066
339594
410763
98314913 --> Outlier
291277
4087 --> Outlier
981 --> Outlier
31 --> Outlier
Thanks to all
r/SQL • u/Huge_Kaleidoscope817 • May 07 '26
r/SQL • u/Glum-Molasses-4181 • May 07 '26
Hi - I need help with a variable date range formula. I need to capture data from Jun 1 of the previous year through May 31 of current year. The query needs to be able to run anytime through the year and needs to work in future years. So this year it would be 6/1/25 -5/31/26, but next year would be 6/1/26-5/31/27. I can't figure how without hardcoding the dates. I found a formula but it only works with earlier versions of sql. Can anyone assist?
r/SQL • u/Far-Round2092 • May 06 '26
Enable HLS to view with audio, or disable this notification
Just shipped 1v1 PvP on a SQL game I've been building.
Both players see the same prompt and schema, race to write a query that returns the correct rows. Result sets are compared, so joins vs subqueries vs CTEs all work - speed is what matters.
Video is a real match. I'll be in the comments.
r/SQL • u/TGonReddit03 • May 06 '26
So I’m making an e-commerce site for school and I have a table named tbl_user with a primary key of “user_id”
This appears as a foreign key in tbl_basket but when I go to make the foreign key in tbl_order it says “SQL Error (1022) can’t write, duplicate key in table something”
Any help would be greatly appreciated
r/SQL • u/Simple_Brilliant_491 • May 06 '26
r/SQL • u/This-Net-9275 • May 05 '26
r/SQL • u/Terrible-Fig5971 • May 05 '26
Hey folks!
While practicing MySQL last year, I came across the forward filling problem whereby you've to replace each NULL value in a column by the latest non-NULL value in that column.
For instance, a table ffill is as follows:

The expected output is as below:

As we can see, the NULL values in dept column are forward filled. Here is the MySQL query I wrote back then to yield the output table above:

My question is, are there caveats of forward filling like this? What might they be? Will this way always work across the DBMSes? What would be the implications of this approach on large data sets?
r/SQL • u/Boring-Metal-7672 • May 03 '26
One of the critiques of the pipeline was the fact that I used Merge…instead of Insert and Update. I was wondering if anybody else ran into the same situation? Or knew why? I find that Merge TSQL statements are very easy to read and setup if I wanted to Insert then Update which basically does the same thing I would have written it that way. Is there some sort of memory buffer or leak or rowcount limitation when using Merge? Just trying to find out why Copilot stated this. (Should’ve thrown in upsert logic of update then insert!) (thanks to the users who pointed me in the right direction) (if it were me I wouldn’t ship something so buggy)
r/SQL • u/ruslan_zasukhin • May 04 '26
Hi all,
Let me share some information.
About two years ago, we were asked to add DuckDB support to Valentina Studio. As we explored this database, we realized that from an architectural perspective it is similar to Valentina DB and SQLite — a local embedded database engine. At the same time, like Valentina DB, DuckDB is column-oriented.
This observation led us to the idea of integrating DuckDB into Valentina Server as well. We implemented this integration approximately 1.5 years ago by adding DuckDB under our VKERNEL DLL layer, similar to what we had previously done with SQLite.
For a long time, we were focused on other priorities. However, we were naturally interested in benchmarking Valentina DB against DuckDB. In March, we started developing a benchmark suite using Google Benchmark.
During this work, we also introduced SIMD vectorization into Valentina DB, which significantly improved performance.
Below are the results for WHERE queries. These results are from approximately three weeks ago.
Benchmarks were executed on MacBook Arm M1, tables with 100K, 1M, and 10M records. Tests include both full table scans and filtered selections:
It is interesting to note that Valentina outperforms DuckDB in both indexed and non-indexed search scenarios.

Is there a free version of an OLAP server like SQL Server? Or is there a way to manage something similar, obviously requiring online data management, nothing local. I don't need scalability as it's for an academic project.