B
B
beduin012021-12-09 09:24:51
PostgreSQL
beduin01, 2021-12-09 09:24:51

How are UPDATE requests executed?

It was required to update the big table. Such questions.
1. Does it matter if the UPDATE query is split into parts? Type instead of one large 10 smaller ones. For example, with a distinction between dates. If yes, what is the reason?
2. If queries are separated by a semicolon, are they performed within the same transaction or does the semicolon limit the transaction? It's about SQL Manager.

The second question arose because:
select * from pg_stat_activity

Indicates (query column) that 10 queries are running at the same time:
update table1 set a='1' where ... ;
update table2 set a='1' where ... ;
update table3 set a='1' where ... ;

It turns out that they are not one by one, but within the framework of one large transaction, and if I interrupt on the last one, everything will be rolled back and it will be considered that the update did not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-12-09
@beduin01

1. Does it matter if the UPDATE query is split into parts? Type instead of one large 10 smaller ones. For example, with a distinction between dates. If yes, what is the reason?

See what difference interests you. Of course, one large request is one large transaction, and small ones can be performed in several. I think there is no need to explain the difference?
One large transaction can create a load on the server, in particular, block table rows and parallel queries that work with them. Also, WAL will continuously grow during the entire duration of the transaction. For very large updates, this is critical.
2. If queries are separated by a semicolon, are they performed within the same transaction or does the semicolon limit the transaction? It's about SQL Manager.

It depends on the client. If the client sends them in one protocol message (in one PQexec call, for example), then in one transaction .
The client, in theory, can himself try to break the request into parts and send one at a time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question