Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlXEh-003EWX-7F for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 16:18:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qlXEf-000xqR-FP for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 16:18:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlXEe-000xq7-PF for pgsql-hackers@lists.postgresql.org; Wed, 27 Sep 2023 16:18:01 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qlXEc-006xKZ-FW for pgsql-hackers@lists.postgresql.org; Wed, 27 Sep 2023 16:18:00 +0000 Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-690f2719ab2so2654018b3a.0 for ; Wed, 27 Sep 2023 09:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695831477; x=1696436277; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=rFVLVS+Zlo0IZNe0w6fGhfs8AWdk4hCCWbYwyUhmTRk=; b=S+8uyCQ6FR4oorhAYsdwnjSfSrxe3VP9tD0cq3N+QLbk5Wpghr9QT9VFsrTN5i8GfC PENPPaCRm/K3B8vR1ds7rUoNwa5jz/X2oCzvMCSKqmTwtr4D8ExDNYSlt8Qebqj6Sp3i tqNHuze12UPpRs+H6LvLqYoihpQoSvtOYEKvyWqcugcY5/t1E8q9Bivou6jAR+ic8870 rslsrVyo0TeROcf212r7T1IuDd4SKAx7rsufL3nadpe+2pwZyLvRFhZSXFT3L/7fBFme oodFVZpPYAE4z22/8sBjnWwo5j76XbyeN9M+uxdLyRKBNXEQHhZ7/v4qWKUxgSLbA2jU n55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695831477; x=1696436277; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rFVLVS+Zlo0IZNe0w6fGhfs8AWdk4hCCWbYwyUhmTRk=; b=UEH31DLzDUan5PiGuONF1ZKrQc/emfEaFk7z2OQP3tvR5RLvagKkINkZww86nalieh 01NaOp4tCXfPx0/d7mBoMgPiursvnMvp9+yebcpGyeNiaf2P6ILgUToHfxs6xgEEZ1nV p6V93E9tA7seRSej00wkKEq0+JUdAcgmh/4CpLDId3DItcsKX5Y4jP5d6ym7ZcK7qYmw t9h5XMBJbPy8qiFlVyQ4D9Yfs8Q04NLdLq38ZSpt6j2Vd6hdgOVbcvl97ZfsZOnyuFIT ey7BqkfP53Wxw3xr51QFDP86vwXB8pwd9lSKSsKkyriTW8sGOl0YWmbRWBnj4yPaP3Tq wdmQ== X-Gm-Message-State: AOJu0YxyoWwSpsyiZi/79OyWNoJQRGN6X8y/OpJhQzu78JsGLBHcwirA qpp1HwQsBMGmLKW9jcVSSPbWuWx5bE+SvtJT X-Google-Smtp-Source: AGHT+IHwTisUCt0xSAla6211KjVXsdn5sbmeNYGocjFwYyNyp2fhaSui2TmlTWoY7/XBCQZPfYcbMw== X-Received: by 2002:a05:6a21:7895:b0:133:6e3d:68cd with SMTP id bf21-20020a056a21789500b001336e3d68cdmr2559687pzc.3.1695831476525; Wed, 27 Sep 2023 09:17:56 -0700 (PDT) Received: from smtpclient.apple ([2406:da18:731:2200:2dbf:c8ab:925:93a8]) by smtp.gmail.com with ESMTPSA id u4-20020a17090a518400b00268dac826d4sm13154614pjh.0.2023.09.27.09.17.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Sep 2023 09:17:56 -0700 (PDT) From: jacktby jacktby Message-Id: <947FA470-EB53-4975-89E1-69ACCFDED649@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_827C8D36-05EB-45E5-AFD7-BB5D79366769" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: Index AmInsert Parameter Confused? Date: Thu, 28 Sep 2023 00:17:43 +0800 In-Reply-To: Cc: boekewurm+postgres@gmail.com To: pgsql-hackers@lists.postgresql.org References: <8ADD1D60-2F10-44CF-A9B1-7D1824D48C36@gmail.com> <0DE3162E-375E-439C-A104-11E37B97BE5D@gmail.com> X-Mailer: Apple Mail (2.3731.600.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_827C8D36-05EB-45E5-AFD7-BB5D79366769 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 2023=E5=B9=B49=E6=9C=8827=E6=97=A5 18:08=EF=BC=8CMatthias van de Meent = =E5=86=99=E9=81=93=EF=BC=9A >=20 > On Wed, 27 Sept 2023 at 05:03, jacktby jacktby > wrote: >>=20 >>=20 >>=20 >>> 2023=E5=B9=B49=E6=9C=8827=E6=97=A5 00:45=EF=BC=8CMatthias van de = Meent =E5=86=99=E9=81=93=EF=BC=9A >>>=20 >>> On Tue, 26 Sept 2023 at 18:38, jacktby jacktby = wrote: >>>>=20 >>>> typedef bool (*aminsert_function) (Relation indexRelation, >>>> Datum *values, >>>> bool *isnull, >>>> ItemPointer heap_tid, >>>> Relation heapRelation, >>>> IndexUniqueCheck checkUnique, >>>> bool indexUnchanged, >>>> struct IndexInfo *indexInfo); >>>>=20 >>>> Why is there a heap_tid, We haven=E2=80=99t inserted the value, so = where does it from ? >>>=20 >>> Index insertion only happens after the TableAM tuple has been >>> inserted. As indexes refer to locations in the heap, this TID = contains >>> the TID of the table tuple that contains the indexed values, so that >>> the index knows which tuple to refer to. >>>=20 >>> Note that access/amapi.h describes only index AM APIs; it does not >>> cover the table AM APIs descibed in access/tableam.h >>>=20 >>> Kind regards, >>>=20 >>> Matthias van de Meent >> 1.Thanks, so if we insert a tuple into a table which has a index on = itself, pg will insert tuple into heap firstly, and the give the heaptid = form heap to the Index am api right? >=20 > Correct. I think this is also detailed in various places of the > documentation, yes. >=20 >> 2. I=E2=80=99m trying to implement a new index, but I just need the = data held in index table, I hope it=E2=80=99s not inserted into heap, = because the all data I want can be in index table. >=20 > In PostgreSQL, a table maintains the source of truth for the data, and > indexes are ephemeral data structures that improve the speed of > querying the data in their table. As such, dropping an index should > not impact the availability of the table's data. > If the only copy of your (non-derived) data is in the index, then it > is likely that some normal table operations will result in failures > due to the tableAM/indexAM breaking built-in assumptions about access > methods and data availability. >=20 > Kind regards, >=20 > Matthias van de Meent > Neon (https://neon.tech ) So do I need to free the ItemPointer and Values in the func implemented = by myself?= --Apple-Mail=_827C8D36-05EB-45E5-AFD7-BB5D79366769 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

2023=E5=B9=B49=E6=9C=8827=E6=97=A5 18:08=EF=BC=8CMatthi= as van de Meent <boekewurm+postgres@gmail.com> =E5=86=99=E9=81=93=EF= =BC=9A

On Wed, 27 Sept 2023 at = 05:03, jacktby jacktby <jacktby@gmail.com> wrote:



2023=E5=B9=B49=E6=9C=8827=E6=97=A5 00:45=EF=BC=8CMatthias = van de Meent <boekewurm+postgres@gmail.com> =E5=86=99=E9=81=93=EF=BC= =9A

On Tue, 26 Sept 2023 at 18:38, jacktby jacktby = <jacktby@gmail.com> wrote:

typedef = bool (*aminsert_function) (Relation indexRelation,
Datum = *values,
bool *isnull,
ItemPointer heap_tid,
Relation = heapRelation,
IndexUniqueCheck checkUnique,
bool = indexUnchanged,
struct IndexInfo *indexInfo);

Why is there a = heap_tid, We haven=E2=80=99t inserted the value, so where does it from = ?

Index insertion only happens after the TableAM = tuple has been
inserted. As indexes refer to locations in the heap, = this TID contains
the TID of the table tuple that contains the = indexed values, so that
the index knows which tuple to refer = to.

Note that access/amapi.h describes only index AM APIs; it = does not
cover the table AM APIs descibed in = access/tableam.h

Kind regards,

Matthias van de = Meent
1.Thanks, so if we insert a tuple into a table = which has a index on itself, pg will insert tuple into heap firstly, and = the give the heaptid form heap to the Index am api = right?

Correct. I think this is also detailed in various places of = the
documentation, = yes.

2. I=E2=80=99m trying to implement a new index, = but I just need the data held in index table, I hope it=E2=80=99s not = inserted into heap, because the all data I want can be in index = table.

In = PostgreSQL, a table maintains the source of truth for the data, = and
indexes are ephemeral = data structures that improve the speed of
querying the data in their table. As such, dropping an = index should
not impact the = availability of the table's data.
If the = only copy of your (non-derived) data is in the index, then it
is likely that some normal table operations = will result in failures
due to = the tableAM/indexAM breaking built-in assumptions about access
methods and data availability.

Kind regards,

Matthias van de Meent
Neon = (https://neon.tech)
So do I need to free the = ItemPointer and Values in the func implemented by myself?= --Apple-Mail=_827C8D36-05EB-45E5-AFD7-BB5D79366769--