pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
equivalent thing of mtr in mysql
8+ messages / 5 participants
[nested] [flat]

* equivalent thing of mtr in mysql
@ 2022-07-12 14:39  merryok <merryok@163.com>
  0 siblings, 1 reply; 8+ messages in thread

From: merryok @ 2022-07-12 14:39 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi, guys. I'm new here.


I'm eager to figure out what is the equivalent thing of mtr in mysql in PG. When a dml operation occurs, it may modify multiple pages and gererate multiple redo log records. mtr can make those logs atomically be transferred to log buffer and written to disk. 
I think same situation exists in PG, but I can't find something like mtr, why ?


Any blogs that explain this will be appreciated.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: equivalent thing of mtr in mysql
@ 2022-07-12 18:57  Peter J. Holzer <hjp-pgsql@hjp.at>
  parent: merryok <merryok@163.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Peter J. Holzer @ 2022-07-12 18:57 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2022-07-12 22:39:31 +0800, merryok wrote:
> Hi, guys. I'm new here.
> 
> I'm eager to figure out what is the equivalent thing of mtr in mysql in PG.

What is MTR? A search for "mtr mysql" yields "mysql test run" and
"multi-threaded replication", neither of which seems to be what you are
talking about. When referring to concepts from other databases, please
include a link to the relevant documentation.

> When a dml operation occurs, it may modify multiple pages and gererate multiple
> redo log records. mtr can make those logs atomically be transferred to log
> buffer and written to disk. 
> I think same situation exists in PG, but I can't find something like mtr, why ?

Transactions in PostgreSQL are always atomic (That should also be the
case with MySQL, unless you use MyISAM tables). Ensuring that these
changes also result in an atomic disk write seems to be both pointless
and impossible (that might be many gigabytes of data).

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: equivalent thing of mtr in mysql
@ 2022-07-12 19:07  Rob Sargent <robjsargent@gmail.com>
  parent: Peter J. Holzer <hjp-pgsql@hjp.at>
  1 sibling, 1 reply; 8+ messages in thread

From: Rob Sargent @ 2022-07-12 19:07 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 7/12/22 12:57, Peter J. Holzer wrote:
> On 2022-07-12 22:39:31 +0800, merryok wrote:
>> Hi, guys. I'm new here.
>>
>> I'm eager to figure out what is the equivalent thing of mtr in mysql in PG.
> What is MTR? A search for "mtr mysql" yields "mysql test run" and
> "multi-threaded replication", neither of which seems to be what you are
> talking about. When referring to concepts from other databases, please
> include a link to the relevant documentation.
>
>> When a dml operation occurs, it may modify multiple pages and gererate multiple
>> redo log records. mtr can make those logs atomically be transferred to log
>> buffer and written to disk.
>> I think same situation exists in PG, but I can't find something like mtr, why ?

I thought OP was hinting at WAL stuff defn here 
<https://www.postgresql.org/docs/current/wal-intro.html;
> Transactions in PostgreSQL are always atomic (That should also be the
> case with MySQL, unless you use MyISAM tables). Ensuring that these
> changes also result in an atomic disk write seems to be both pointless
> and impossible (that might be many gigabytes of data).
>
>          hp
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: equivalent thing of mtr in mysql
@ 2022-07-12 19:59  Peter J. Holzer <hjp-pgsql@hjp.at>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Peter J. Holzer @ 2022-07-12 19:59 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 2022-07-12 13:07:41 -0600, Rob Sargent wrote:
> I thought OP was hinting at WAL stuff defn here

So did I.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re:Re: equivalent thing of mtr in mysql
@ 2022-07-16 01:31  merryok <merryok@163.com>
  parent: Peter J. Holzer <hjp-pgsql@hjp.at>
  1 sibling, 1 reply; 8+ messages in thread

From: merryok @ 2022-07-16 01:31 UTC (permalink / raw)
  To: Peter J. Holzer <hjp-pgsql@hjp.at>; +Cc: pgsql-general@lists.postgresql.org

I'm sorry, first time to post a thread. mtr is short for mini-transaction.
About mtr in mysql, we can refer to https://dev.mysql.com/doc/refman/8.0/en/glossary.html or
 https://dev.mysql.com/blog-archive/mysql-8-0-new-lock-free-scalable-wal-design/ 




So an insert in mysql,  wrapped in a user transaction, may result in multiple mini-transactions, one is responsible for writing redo for undo, the other one for writing redo for clustered index/secondary index, and so on. Each mtr may modify multiple pages,  whose redo logs are guaranteed by mtr to be written into disk or none of them are written.











At 2022-07-13 02:57:28, "Peter J. Holzer" <hjp-pgsql@hjp.at> wrote:
>On 2022-07-12 22:39:31 +0800, merryok wrote:
>> Hi, guys. I'm new here.
>> 
>> I'm eager to figure out what is the equivalent thing of mtr in mysql in PG.
>
>What is MTR? A search for "mtr mysql" yields "mysql test run" and
>"multi-threaded replication", neither of which seems to be what you are
>talking about. When referring to concepts from other databases, please
>include a link to the relevant documentation.
>
>> When a dml operation occurs, it may modify multiple pages and gererate multiple
>> redo log records. mtr can make those logs atomically be transferred to log
>> buffer and written to disk. 
>> I think same situation exists in PG, but I can't find something like mtr, why ?
>
>Transactions in PostgreSQL are always atomic (That should also be the
>case with MySQL, unless you use MyISAM tables). Ensuring that these
>changes also result in an atomic disk write seems to be both pointless
>and impossible (that might be many gigabytes of data).
>
>        hp
>
>-- 
>   _  | Peter J. Holzer    | Story must make more sense than reality.
>|_|_) |                    |
>| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
>__/   | http://www.hjp.at/ |       challenge!"


^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: equivalent thing of mtr in mysql
@ 2022-07-16 15:30  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: merryok <merryok@163.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Adrian Klaver @ 2022-07-16 15:30 UTC (permalink / raw)
  To: merryok <merryok@163.com>; Peter J. Holzer <hjp-pgsql@hjp.at>; +Cc: pgsql-general@lists.postgresql.org

On 7/15/22 18:31, merryok wrote:
> I'm sorry, first time to post a thread. mtr is short for mini-transaction.
> About mtr in mysql, we can refer to 
> https://dev.mysql.com/doc/refman/8.0/en/glossary.html 
> <https://dev.mysql.com/doc/refman/8.0/en/glossary.html> or
> https://dev.mysql.com/blog-archive/mysql-8-0-new-lock-free-scalable-wal-design/ 
> <https://dev.mysql.com/blog-archive/mysql-8-0-new-lock-free-scalable-wal-design/; 
> 
> 
> 
> So an insert in mysql,  wrapped in a user transaction, may result in 
> multiple mini-transactions, one is responsible for writing redo for 
> undo, the other one for writing redo for clustered index/secondary 
> index, and so on. Each mtr may modify multiple pages,  whose redo logs 
> are guaranteed by mtr to be written into disk or none of them are written.
> 

Read this:

https://www.postgresql.org/docs/current/wal.html

and see if it answers your questions.


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: equivalent thing of mtr in mysql
@ 2022-07-19 03:03  merryok <merryok@163.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 8+ messages in thread

From: merryok @ 2022-07-19 03:03 UTC (permalink / raw)
  To: adrian.klaver@aklaver.com; hjp-pgsql@hjp.at; +Cc: pgsql-general@lists.postgresql.org

<div dir="ltr">I&#39;ve read the doc, and it doesn&#39;t help too much.<br>
</div><div dir="ltr">Finally I&#39;ve found START_CRIT_SECTION and END_CRIT_SECTION. It&#39;s like mtr.start(), mtr.commit() in mysql. May I ask why many places are wrapped into START_CRIT_SECTION/END_CRIT_SECTION during a single dml operation ?<br>
</div><div dir="ltr"><br>
</div><div dir="ltr">And if Assert(CritSectionCount &gt; 0) isn&#39;t satisfied (CritSectionCount need&#39;t be protected ?), PG server will panic and exit ? If so, what&#39;s the probability of that ?<br>
</div><div dir="ltr"><br>
</div><div dir="ltr"><br>
</div><div dir="ltr"><br>
</div><div dir="ltr"><br>
</div><div dir="ltr"><br>
</div><div class="wps_signature">发自我的小米手机</div><div class="wps_quotion">在 Adrian Klaver &lt;adrian.klaver@aklaver.com&gt;,2022年7月16日 23:30写道:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p></p><p dir="ltr">On 7/15/22 18:31, merryok wrote:
<br>
&gt; I&#39;m sorry, first time to post a thread. mtr is short for mini-transaction.
<br>
&gt; About mtr in mysql, we can refer to 
<br>
&gt; <a href="https://dev.mysql.com/doc/refman/8.0/en/glossary.html">https://dev.mysql.com/doc/refman/8.0/e...; 
<br>
&gt; &lt;<a href="https://dev.mysql.com/doc/refman/8.0/en/glossary.html">https://dev.mysql.com/doc/refman/8.0/e...
<br>
&gt; <a href="https://dev.mysql.com/blog-archive/mysql-8-0-new-lock-free-scalable-wal-design">https://dev.m... 
<br>
&gt; &lt;<a href="https://dev.mysql.com/blog-archive/mysql-8-0-new-lock-free-scalable-wal-design">https://dev.m...; 
<br>
&gt; 
<br>
&gt; 
<br>
&gt; 
<br>
&gt; So an insert in mysql,  wrapped in a user transaction, may result in 
<br>
&gt; multiple mini-transactions, one is responsible for writing redo for 
<br>
&gt; undo, the other one for writing redo for clustered index/secondary 
<br>
&gt; index, and so on. Each mtr may modify multiple pages,  whose redo logs 
<br>
&gt; are guaranteed by mtr to be written into disk or none of them are written.
<br>
&gt; 
<br>

<br>
Read this:
<br>

<br>
<a href="https://www.postgresql.org/docs/current/wal.html">https://www.postgresql.org/docs/current/wal...;
<br>

<br>
and see if it answers your questions.
<br>

<br>

<br>
-- 
<br>
Adrian Klaver
<br>
<a href="mailto:adrian.klaver@aklaver.com">adrian.klaver@aklaver.com</a>
<br>
</p>
</blockquote></div>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: equivalent thing of mtr in mysql
@ 2022-07-19 03:24  Christophe Pettus <xof@thebuild.com>
  parent: merryok <merryok@163.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Christophe Pettus @ 2022-07-19 03:24 UTC (permalink / raw)
  To: merryok <merryok@163.com>; +Cc: adrian.klaver@aklaver.com; hjp-pgsql@hjp.at; pgsql-general@lists.postgresql.org



> On Jul 18, 2022, at 20:03, merryok <merryok@163.com> wrote:
> 
> I've read the doc, and it doesn't help too much.
> Finally I've found START_CRIT_SECTION and END_CRIT_SECTION. It's like mtr.start(), mtr.commit() in mysql. May I ask why many places are wrapped into START_CRIT_SECTION/END_CRIT_SECTION during a single dml operation ?

A PostgreSQL critical section is not the equivalent of MySQL InnoDB mini-transaction.

A critical section in PostgreSQL is a section of code that needs to run without interruption to avoid corruption of internal in-memory data structures.

PostgreSQL doesn't have a direct equivalent of a MySQL mini-transaction.  When WAL information is created by a statement, it's stored in the WAL buffers, and then flushed to disk by the WAL writer (to a first approximation).  There's no special operation that groups pages together for atomic writes; that's done by the underlying file system flush operation.

> And if Assert(CritSectionCount > 0) isn't satisfied (CritSectionCount need't be protected ?), PG server will panic and exit ? If so, what's the probability of that ?

If it occurs, it indicates a bug in PostgreSQL.  It is *extremely* infrequent (as in, you can go years without seeing one; I can't remember the last time I did).




^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2022-07-19 03:24 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 14:39 equivalent thing of mtr in mysql merryok <merryok@163.com>
2022-07-12 18:57 ` Peter J. Holzer <hjp-pgsql@hjp.at>
2022-07-12 19:07   ` Rob Sargent <robjsargent@gmail.com>
2022-07-12 19:59     ` Peter J. Holzer <hjp-pgsql@hjp.at>
2022-07-16 01:31   ` merryok <merryok@163.com>
2022-07-16 15:30     ` Adrian Klaver <adrian.klaver@aklaver.com>
2022-07-19 03:03       ` merryok <merryok@163.com>
2022-07-19 03:24         ` Christophe Pettus <xof@thebuild.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox