*** a/doc/src/sgml/catalogs.sgml
--- b/doc/src/sgml/catalogs.sgml
***************
*** 719,725 ****
        <entry><structfield>amcanreturn</structfield></entry>
        <entry><type>regproc</type></entry>
        <entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
!       <entry>Function to check whether index supports index-only scans,
         or zero if none</entry>
       </row>
  
--- 719,725 ----
        <entry><structfield>amcanreturn</structfield></entry>
        <entry><type>regproc</type></entry>
        <entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
!       <entry>Function to check whether index column supports index-only scans,
         or zero if none</entry>
       </row>
  
*** a/doc/src/sgml/gist.sgml
--- b/doc/src/sgml/gist.sgml
***************
*** 266,272 **** CREATE INDEX ON my_table USING gist (my_inet_column inet_ops);
  
   <para>
     There are seven methods that an index operator class for
!    <acronym>GiST</acronym> must provide, and an eighth that is optional.
     Correctness of the index is ensured
     by proper implementation of the <function>same</>, <function>consistent</>
     and <function>union</> methods, while efficiency (size and speed) of the
--- 266,272 ----
  
   <para>
     There are seven methods that an index operator class for
!    <acronym>GiST</acronym> must provide, and two that are optional.
     Correctness of the index is ensured
     by proper implementation of the <function>same</>, <function>consistent</>
     and <function>union</> methods, while efficiency (size and speed) of the
***************
*** 282,288 **** CREATE INDEX ON my_table USING gist (my_inet_column inet_ops);
     of the <command>CREATE OPERATOR CLASS</> command can be used.
     The optional eighth method is <function>distance</>, which is needed
     if the operator class wishes to support ordered scans (nearest-neighbor
!    searches).
   </para>
  
   <variablelist>
--- 282,289 ----
     of the <command>CREATE OPERATOR CLASS</> command can be used.
     The optional eighth method is <function>distance</>, which is needed
     if the operator class wishes to support ordered scans (nearest-neighbor
!    searches). The optional ninth method <function>fetch</> is required to provide
!    an opportunity for operator class to support index-only scan.
   </para>
  
   <variablelist>
***************
*** 813,818 **** my_distance(PG_FUNCTION_ARGS)
--- 814,897 ----
       </listitem>
      </varlistentry>
  
+     <varlistentry>
+      <term><function>fetch</></term>
+      <listitem>
+       <para>
+       The method of retrieving data from the index page without loss. Converts the
+        index representation of the data item into a suitable format.
+       </para>
+ 
+       <para>
+         The <acronym>SQL</> declaration of the function must look like this:
+ 
+ <programlisting>
+ CREATE OR REPLACE FUNCTION my_fetch(internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT;
+ </programlisting>
+ 
+         And the matching code in the C module could then follow this skeleton:
+ 
+ <programlisting>
+ Datum       my_fetch(PG_FUNCTION_ARGS);
+ PG_FUNCTION_INFO_V1(my_fetch);
+ 
+ Datum
+ my_fetch(PG_FUNCTION_ARGS)
+ {
+ GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY  *retval;
+       /*
+        * return data from index into output slot in appropriate datatype
+        */
+       retval = palloc(sizeof(GISTENTRY));
+            if (DatumGetP(entry->key) != NULL)
+            {
+                 input_data_type *in = DatumGetP(entry->key);
+                 fetched_data_type *fetched_data = palloc(sizeof(fetched_data_type));
+ 
+            /*
+             * computations that are necessary to get fetched_data formatted as it storaged in table
+             */
+ 
+            /* 
+             * fill *fetched_data from entry-&gt;key ... 
+             */
+                 gistentryinit(*retval, PointerGetDatum(fetched_data),
+                                        entry->rel, entry->page,
+                                                    entry->offset, FALSE);
+ 
+            }
+            else
+            {
+                 gistentryinit(*retval, (Datum) 0,
+                                        entry->rel, entry->page,
+                                                    entry->offset, FALSE);
+            }
+ 
+ PG_RETURN_POINTER(retval);
+ }
+ </programlisting>
+       </para>
+ 
+       <para>
+       Attention:
+       Gistcanreturn is supposed to be true for opclass if ANY <function>fetch</> 
+       method is defined. If <function>fetch</> function exists it would be used in 
+       index-only scan. Thus the responsibility rests with the opclass developer. 
+       </para>
+ 
+       <para>
+       If compress method is not lossy, opclass could in principle support index-only scans.
+       One must be careful with calculations inside <function>fetch</> function. 
+       If conversions lose some precision due to rounding, query result will be 
+       wrong. Such behaviour is not allowed for any scan plan.      
+       </para>
+ 
+      </listitem>
+     </varlistentry>
    </variablelist>
  
    <para>
*** a/doc/src/sgml/indexam.sgml
--- b/doc/src/sgml/indexam.sgml
***************
*** 274,282 **** amvacuumcleanup (IndexVacuumInfo *info,
    <para>
  <programlisting>
  bool
! amcanreturn (Relation indexRelation);
  </programlisting>
!    Check whether the index can support <firstterm>index-only scans</> by
     returning the indexed column values for an index entry in the form of an
     IndexTuple.  Return TRUE if so, else FALSE.  If the index AM can never
     support index-only scans (an example is hash, which stores only
--- 274,282 ----
    <para>
  <programlisting>
  bool
! amcanreturn (Relation indexRelation, int attno);
  </programlisting>
!    Check whether the index column can support <firstterm>index-only scans</> by
     returning the indexed column values for an index entry in the form of an
     IndexTuple.  Return TRUE if so, else FALSE.  If the index AM can never
     support index-only scans (an example is hash, which stores only