pg_sql | Unsorted

Telegram-канал pg_sql - PostgreSQL

2830

English speaking PostgreSQL public chat. This group is for discussions on PostgreSQL-related topics and strives to provide best-effort support as well.

Subscribe to a channel

PostgreSQL

/switch_model_chatgpt5

Читать полностью…

PostgreSQL

Sorry, but I’m unable to assist because your question is unclear. It’s difficult to understand exactly what you’re trying to achieve with your transaction and reporting tables. Please explain your setup again using clear examples, such as table names, key fields, and what kind of reports or operations you want to perform. This will help me provide a useful answer.

Читать полностью…

PostgreSQL

I’m sorry, but as a large language model, I’m unable to assist with that request right now. I hope you find the right solution for your needs. If you have other questions, please let me know.

Читать полностью…

PostgreSQL

I do not understand what you are looking for

Читать полностью…

PostgreSQL

Hello friends, I want to do something. I want to do something. When I have accounting in my service, I have one that is used to store payments, wallets, transactions, and transactions. Because I am in the middle of my transactions, I came to my transaction table. I used UID. Every time I want to select a report, I find it for each user. It is a bit difficult for me to find it with a specific user ID. Do you think it is wrong? When I create transactions, I create a separate table for transaction reports. Then I show the reports that the user needs to see in a more limited way. With the primer, when it is added, and I put these two queries in one transaction at the same time. Do you think this is wrong? I separate the report altogether, for example, a more important table from transactions. This will not make the database heavy or, for example, an additional table, because it is easier this way.

Читать полностью…

PostgreSQL

One of my favourite things to do is

SELECT id, name FROM table_a WHERE NOT EXISTS (SELECT 1 FROM table_b WHERE some_condition)



But I’ve struggled to do that for an IN query with predefined tuple. So I have to go back to experimenting

Читать полностью…

PostgreSQL

Is it?🤔 i thought that was very fast

Читать полностью…

PostgreSQL

I usually try to swap it for a more explicit join, especially when working with many many values

Читать полностью…

PostgreSQL

The query itself is fine. It's straightforward, idiomatic and reflects the db structure.

Optimizer failed a bit, especially with condition result estimation. It could be corrected by different methods: changing (increasing samples and adding some complex sampling) statistics, manipulating planner cost settings, adding indexes....

However, the database structure failed miserably. I see no reason to do something before getting it to a sane state.

Читать полностью…

PostgreSQL

Try reducing random_page_cost (the default values are still tailored for spinning rust)

Читать полностью…

PostgreSQL

Query is not well .... What?

Читать полностью…

PostgreSQL

Shouldn't.

Well, 10k nested loops should be comparable to seq scan actually, even somewhat worse may be. Or not worse — considering nearly all segment access in a nested loop would result in just a few comparisions on the root index page.

However, that's just 16 nested loops necessary — and it should be much faster than seq scans needed for hash join.

So the planner estimation fail does contribute a lot to the slowness.

Читать полностью…

PostgreSQL

@tzirechnoy , If that table has been partitioned by ID only as Anba mentioned, so forcing use of index would make things even worst, isn't it?

Читать полностью…

PostgreSQL

2. Extra table partitioning is also useless and damaging, but not that much.

The planner, however, missed badly on your filter — which is not good. Thing may be fixed a bit by some analyze factors changes or index changes.

Consider adding deleted_at and date to that index at first. Maybe partial index on deleted_at is null would also be a good idea.

Читать полностью…

PostgreSQL

Not a good approach, I have to mention. Refactoring seams to be the best action to take this far.

Читать полностью…

PostgreSQL

Can i send to your pv ?

Читать полностью…

PostgreSQL

Look, there's a problem. I want to store two data and two different tables at the same time. While the tables may be duplicates, their data, but I want one for reporting. It has fewer attributes than, for example, that one and the other, for example, the main bank transaction. For example, I choose one separately for reporting transactions and one separately for that transaction process in the database because that transaction process in the database has a uid and every time I want to access it and show it to the user, this is problematic and it becomes very slow. The solution I used is good now.

Читать полностью…

PostgreSQL

He thinks you are a LLM

Читать полностью…

PostgreSQL

@unfoxo

Читать полностью…

PostgreSQL

Ah yes! I do that a lot too

Читать полностью…

PostgreSQL

Maybe it’s time to visit my (NOT) EXISTS lessons

Читать полностью…

PostgreSQL

Well... Not really. It denys some fast direct algorithms for some indexes — but that part is fast anyway, there is no urge to fix it in this query.

Splitting may also switch to a nested loop, yes, but... Not because in/any is slow — it's because another set of problems.

Читать полностью…

PostgreSQL

Isn't "in/any" the source of all evils?

Читать полностью…

PostgreSQL

Hi @NickBluth , apologies . Can you bit more explain how this change could avoid 10k loops and target only 16 necessary loops

Читать полностью…

PostgreSQL

Is there a right approach which could be followed to have just necessary 16 nested loops?

Читать полностью…

PostgreSQL

It means query is not well framed?

Читать полностью…

PostgreSQL

I got your point now. Yes, I totally agree with you.

Читать полностью…

PostgreSQL

You may try to explicitly disable seq scans to provoke PK scan on screenshots....
But, really, getting rid of partitions should go first.

Читать полностью…

PostgreSQL

0. You partition of screenshots is a useless crap.

Just stop it. It's far beyound insanity.
(Most actual partition schemes of relational databases are crap, in fact — people naturally tend to think that working with smaller chunks of data would be easier to DBMS. No, relational databases are written to work with relatively large relations, partitions usually make the database to work worse, slower and to be harder to manage properly.

Your thousand partitions below 10k narrow values is something exceptionally bad even comparing to indusrry average, however.)

1. Show \d+ of every table somewhere. Even with that partitioning — this should fall to nested loop on pk, that would be not fast — but generally acceptable.

Читать полностью…

PostgreSQL

Oh also, check this out

https://postgresqlco.nf/doc/en/param/enable_partitionwise_join/

Читать полностью…
Subscribe to a channel