Re: Index AmInsert Parameter Confused?

2023-09-27 Thread jacktby jacktby


> 2023年9月27日 18:08,Matthias van de Meent  写道:
> 
> On Wed, 27 Sept 2023 at 05:03, jacktby jacktby  > wrote:
>> 
>> 
>> 
>>> 2023年9月27日 00:45,Matthias van de Meent  写道:
>>> 
>>> On Tue, 26 Sept 2023 at 18:38, jacktby jacktby  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’t 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’m trying to implement a new index, but I just need the data held in 
>> index table, I hope it’s 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?

Re: Index AmInsert Parameter Confused?

2023-09-27 Thread Matthias van de Meent
On Wed, 27 Sept 2023 at 05:03, jacktby jacktby  wrote:
>
>
>
> > 2023年9月27日 00:45,Matthias van de Meent  写道:
> >
> > On Tue, 26 Sept 2023 at 18:38, jacktby jacktby  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’t 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’m trying to implement a new index, but I just need the data held in 
> index table, I hope it’s 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)




Re: Index AmInsert Parameter Confused?

2023-09-26 Thread jacktby jacktby



> 2023年9月27日 00:45,Matthias van de Meent  写道:
> 
> On Tue, 26 Sept 2023 at 18:38, jacktby jacktby  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’t 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?
2. I’m trying to implement a new index, but I just need the data held in index 
table, I hope it’s not inserted into heap, because the all data I want can be 
in index table.



Re: Index AmInsert Parameter Confused?

2023-09-26 Thread Matthias van de Meent
On Tue, 26 Sept 2023 at 18:38, jacktby jacktby  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’t 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




Index AmInsert Parameter Confused?

2023-09-26 Thread jacktby jacktby
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’t inserted the value, so where does it from ?