-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,118 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- doc/src/sgml/tableam.sgml --> | ||
|
||
<chapter id="tableam"> | ||
<title>Table Access Method Interface Definition</title> | ||
<title>Définition de l'interface des méthodes d'accès aux tables</title> | ||
|
||
<indexterm> | ||
<primary>Table Access Method</primary> | ||
<primary>Méthode d'accès aux tables</primary> | ||
</indexterm> | ||
<indexterm> | ||
<primary>tableam</primary> | ||
<secondary>Table Access Method</secondary> | ||
<secondary>Méthode d'accès aux tables</secondary> | ||
</indexterm> | ||
|
||
<para> | ||
This chapter explains the interface between the core | ||
<productname>PostgreSQL</productname> system and <firstterm>table access | ||
methods</firstterm>, which manage the storage for tables. The core system | ||
knows little about these access methods beyond what is specified here, so | ||
it is possible to develop entirely new access method types by writing | ||
add-on code. | ||
Ce chapitre explique l'interface entre le système | ||
<productname>PostgreSQL</productname> et les <firstterm>méthodes d'accès aux | ||
tables</firstterm>, qui gèrent le stockage des tables. Le cœur du système | ||
connaît très peu de choses sur ces méthodes d'accès en dehors de ce qui est | ||
spécifié ici, donc il est possible de développer de nouvelles méthodes | ||
d'accès en écrivant un code supplémentaire. | ||
</para> | ||
|
||
<para> | ||
Each table access method is described by a row in the <link | ||
linkend="catalog-pg-am"><structname>pg_am</structname></link> system | ||
catalog. The <structname>pg_am</structname> entry specifies a name and a | ||
<firstterm>handler function</firstterm> for the table access method. These | ||
entries can be created and deleted using the <xref | ||
linkend="sql-create-access-method"/> and <xref | ||
linkend="sql-drop-access-method"/> SQL commands. | ||
Chaque méthode d'accès aux tables est décrite par une ligne dans le | ||
catalogue système <link | ||
linkend="catalog-pg-am"><structname>pg_am</structname></link>. | ||
L'enregistrement dans <structname>pg_am</structname> précise un nom et une | ||
<firstterm>fonction de gestion</firstterm> pour la méthode d'accès à la | ||
table. Ces enregistrements peuvent être créés et supprimés en utilisant les | ||
commandes SQL <xref linkend="sql-create-access-method"/> et <xref | ||
linkend="sql-drop-access-method"/>. | ||
</para> | ||
|
||
<para> | ||
A table access method handler function must be declared to accept a single | ||
argument of type <type>internal</type> and to return the pseudo-type | ||
<type>table_am_handler</type>. The argument is a dummy value that simply | ||
serves to prevent handler functions from being called directly from SQL commands. | ||
Une fonction de gestion de la méthode d'accès aux tables doit être déclarée | ||
comme acceptant un seul argument de type <type>internal</type> et doit | ||
renvoyer le pseudo-type <type>table_am_handler</type>. L'argument est une | ||
valeur bateau qui sert simplement à empêcher l'appel de fonctions de gestion | ||
à partir de simples commandes SQL. | ||
|
||
The result of the function must be a pointer to a struct of type | ||
<structname>TableAmRoutine</structname>, which contains everything that the | ||
core code needs to know to make use of the table access method. The return | ||
value needs to be of server lifetime, which is typically achieved by | ||
defining it as a <literal>static const</literal> variable in global | ||
scope. The <structname>TableAmRoutine</structname> struct, also called the | ||
access method's <firstterm>API struct</firstterm>, defines the behavior of | ||
the access method using callbacks. These callbacks are pointers to plain C | ||
functions and are not visible or callable at the SQL level. All the | ||
callbacks and their behavior is defined in the | ||
<structname>TableAmRoutine</structname> structure (with comments inside the | ||
struct defining the requirements for callbacks). Most callbacks have | ||
wrapper functions, which are documented from the point of view of a user | ||
(rather than an implementor) of the table access method. For details, | ||
please refer to the <ulink url="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/access/tableam.h;hb=head"> | ||
<filename>src/include/access/tableam.h</filename></ulink> file. | ||
Le résultat de la fonction doit être un pointeur vers une structure de type | ||
<structname>TableAmRoutine</structname>, qui contient tout ce que le cœur du | ||
moteur a besoin de savoir pour utiliser la méthode d'accès aux tables. La | ||
valeur de retour doit avoir une durée de vie valable pour toute la durée | ||
d'exécution du serveur, ce qui se fait habituellement en la définissant | ||
comme une variable de type <literal>static const</literal> de façon globale. | ||
La structure <structname>TableAmRoutine</structname>, aussi appelée | ||
<firstterm>structure API</firstterm> de la méthode d'accès, définit le | ||
comportement de la méthode d'accès en utilisant des callbacks. Ces callbacks | ||
sont des pointeurs vers des fonctions C et ne sont pas visibles ou | ||
appelables au niveau du langage SQL. Tous les callbacks et leurs | ||
comportements sont définis dans la structure | ||
<structname>TableAmRoutine</structname> (avec des commentaires dans le | ||
structure définissant les prérequis des callbacks). La plupart des callbacks | ||
ont des fonctions wrapper, documentées du point de vue de l'utilisateur | ||
(plutôt que de l'implémenteur) de la méthode d'accès aux tables. Pour les | ||
détails, voir le fichier <ulink | ||
url="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/access/tableam.h;hb=head"> | ||
<filename>src/include/access/tableam.h</filename></ulink>. | ||
</para> | ||
|
||
<para> | ||
To implement an access method, an implementor will typically need to | ||
implement an AM-specific type of tuple table slot (see | ||
<ulink url="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/executor/tuptable.h;hb=head"> | ||
<filename>src/include/executor/tuptable.h</filename></ulink>), which allows | ||
code outside the access method to hold references to tuples of the AM, and | ||
to access the columns of the tuple. | ||
Pour implémenter une méthode d'accès, un implémenteur aura habituellement | ||
besoin d'implémenter un type spécifique AM de ligne (voir <ulink | ||
url="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/executor/tuptable.h;hb=head"> | ||
<filename>src/include/executor/tuptable.h</filename></ulink>), qui permet à | ||
du code en dehors de la méthode d'accès de détenir des références sur les | ||
lignes de l'AM, et d'accéder aux colonnes de la ligne. | ||
</para> | ||
|
||
<para> | ||
Currently, the way an AM actually stores data is fairly unconstrained. For | ||
example, it's possible, but not required, to use postgres' shared buffer | ||
cache. In case it is used, it likely makes sense to use | ||
<productname>PostgreSQL</productname>'s standard page layout as described in | ||
<xref linkend="storage-page-layout"/>. | ||
Actuellement, la façon dont un AM enregisrre les données est très peu | ||
contrainte. Par exemple, il est possible, mais non requis, d'utiliser le | ||
cache disque de PostgreSQL. Au cas où il est utilisé, il est sensé | ||
d'utiliser la disposition standard d'une page de | ||
<productname>PostgreSQL</productname> comme décrit dans <xref | ||
linkend="storage-page-layout"/>. | ||
</para> | ||
|
||
<para> | ||
One fairly large constraint of the table access method API is that, | ||
currently, if the AM wants to support modifications and/or indexes, it is | ||
necessary for each tuple to have a tuple identifier (<acronym>TID</acronym>) | ||
consisting of a block number and an item number (see also <xref | ||
linkend="storage-page-layout"/>). It is not strictly necessary that the | ||
sub-parts of <acronym>TIDs</acronym> have the same meaning they e.g. have | ||
for <literal>heap</literal>, but if bitmap scan support is desired (it is | ||
optional), the block number needs to provide locality. | ||
Une importante contrainte de l'API de méthode d'accès aux tables est | ||
qu'actuellement, si l'AM veut accepter les modifications et/ou les index, il | ||
est nécessaire que chaque ligne ait un identifiant de ligne | ||
(<acronym>TID</acronym>) consistant en un numéro de bloc et un numéro | ||
d'enregistrement (voir aussi <xref linkend="storage-page-layout"/>). IL | ||
n'est pas strictement nécessaire que les sous-parties des | ||
<acronym>TIDs</acronym> aient cette même signification, avoir un | ||
<literal>heap</literal>, mais si le support de parcours de bitmap est | ||
souhaité (c'est optionnel), le numéro de bloc doit fournir une localisation. | ||
</para> | ||
|
||
<para> | ||
For crash safety, an AM can use postgres' <link | ||
linkend="wal"><acronym>WAL</acronym></link>, or a custom implementation. | ||
If <acronym>WAL</acronym> is chosen, either <link | ||
linkend="generic-wal">Generic WAL Records</link> can be used, | ||
or a new type of <acronym>WAL</acronym> records can be implemented. | ||
Generic WAL Records are easy, but imply higher WAL volume. | ||
Implementation of a new type of WAL record | ||
currently requires modifications to core code (specifically, | ||
Pour la sécurité des données, un AM doit utiliser les <link | ||
linkend="wal"><acronym>WAL</acronym></link> de PostgreSQL ou une | ||
implémentation personnalisée. Si les <acronym>WAL</acronym> sont choisis, | ||
des <link linkend="generic-wal">enregistrements génériques des WAL</link> | ||
peuvent être utilisés. Vous pouvez aussi implémenter un nouveau type | ||
d'enregistrements <acronym>WAL</acronym>. Les enregistrements génériques | ||
sont plus simples, mais impliquent un volume WAL plus important. | ||
L'implémentation d'un nouveau type d'enregistrement WAL nécessite | ||
actuellement des modifications du moteur (spécifiquement, | ||
<filename>src/include/access/rmgrlist.h</filename>). | ||
</para> | ||
|
||
<para> | ||
To implement transactional support in a manner that allows different table | ||
access methods be accessed within a single transaction, it likely is | ||
necessary to closely integrate with the machinery in | ||
Pour implémenter le support transactionnel d'une façon qui permet à | ||
différentes méthodes d'accès aux tables d'être accédées dans une seule | ||
transaction, il est généralement nécessaire d'intégrer ce qui se trouve dans | ||
<filename>src/backend/access/transam/xlog.c</filename>. | ||
</para> | ||
|
||
<para> | ||
Any developer of a new <literal>table access method</literal> can refer to | ||
the existing <literal>heap</literal> implementation present in | ||
<filename>src/backend/access/heap/heapam_handler.c</filename> for details of | ||
its implementation. | ||
Tout développeur d'une nouvelle <literal>méthode d'accès aux | ||
tables</literal> peut se référer à l'implémentation existante de | ||
<literal>heap</literal> dans | ||
<filename>src/backend/access/heap/heapam_handler.c</filename> pour les | ||
détails de son implémentation. | ||
</para> | ||
|
||
</chapter> |