pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: jacktby@gmail.com <jacktby@gmail.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Give me details of some attributes!!
Date: Sun, 26 Feb 2023 21:45:03 +0100
Message-ID: <46c39c565e94aed56d678d6fce0ca06c0e081f9e.camel@cybertec.at> (raw)
In-Reply-To: <2023022622292523172412@gmail.com>
References: <2023022622292523172412@gmail.com>

On Sun, 2023-02-26 at 22:29 +0800, jacktby@gmail.com wrote:
> 
> here are the source codes from src/include/access/htup_details.h.
> /*
>  * information stored in t_infomask:
>  */
> #define HEAP_HASNULL			0x0001	/* has null attribute(s) */
> #define HEAP_HASVARWIDTH		0x0002	/* has variable-width attribute(s) */
> #define HEAP_HASEXTERNAL		0x0004	/* has external stored attribute(s) */
> #define HEAP_HASOID_OLD			0x0008	/* has an object-id field */
> #define HEAP_XMAX_KEYSHR_LOCK	0x0010	/* xmax is a key-shared locker */
> #define HEAP_COMBOCID			0x0020	/* t_cid is a combo CID */
> #define HEAP_XMAX_EXCL_LOCK		0x0040	/* xmax is exclusive locker */
> #define HEAP_XMAX_LOCK_ONLY		0x0080	/* xmax, if valid, is only a locker */
> 
> And I can't understand these attrs:
> 1. external stored attribute(s), what is this?  can you give a create statement to show me?

Those are columns stored out of line.  See
https://www.postgresql.org/docs/current/storage-toast.html

> 2. xmax is a key-shared locker/exclusive locker/only a locker, so how you use this? can you give me a  scenario?

https://www.cybertec-postgresql.com/en/whats-in-an-xmax/

> let me try to explain it:
>  if there is a txn is trying to read this heaptuple, the HEAP_XMAX_KEYSHR_LOCK bit will be set to 1.

No, reading a row won't lock it.
It's SELECT ... FOR KEY SHARE that does that.

>  if there is a txn is trying to delete/update this heaptuple, the HEAP_XMAX_EXCL_LOCK bit will be set to 1.

Correct.

>  but for HEAP_XMAX_LOCK_ONLY, I can't understand.

See the comment a few source lines below:

/*
 * A tuple is only locked (i.e. not updated by its Xmax) if the
 * HEAP_XMAX_LOCK_ONLY bit is set; or, for pg_upgrade's sake, if the Xmax is
 * not a multi and the EXCL_LOCK bit is set.

Essentially, it is set after SELECT ... FOR UPDATE.

> And another thought is that these three bit can have only one to be set 1 at most.

If a tuple is only locked FOR KEY SHARE, bit not updated or deleted, both are set.

> 3. t_cid is a combo CID? what's a CID? give me an example please.

The command ID of the command in the transaction.

Yours,
Laurenz Albe





view thread (2+ messages)

Message-ID: <46c39c565e94aed56d678d6fce0ca06c0e081f9e.camel@cybertec.at>
Permalink:  ../46c39c565e94aed56d678d6fce0ca06c0e081f9e.camel@cybertec.at/
Also on:    postgresql.org/message-id/46c39c565e94aed56d678d6fce0ca06c0e081f9e.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, jacktby@gmail.com
  Subject: Re: Give me details of some attributes!!
  In-Reply-To: <46c39c565e94aed56d678d6fce0ca06c0e081f9e.camel@cybertec.at>
  References: <2023022622292523172412@gmail.com> <46c39c565e94aed56d678d6fce0ca06c0e081f9e.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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