Hi,

On 2018/11/26 11:05, Tatsuro Yamada wrote:
Hi,

Attached patches are following:

* tab_completion_alter_index_set_statistics.patch
     - Add column name completion after ALTER COLUMN
     - Avoid schema completion after SET STATISTICS

* fix_manual_of_alter_index.patch
     - ALTER INDEX ALTER COLUMN syntax is able to use not only
       column number but also column name. So, I fixed the manual.

* tab_completion_alter_table_set_statistics.patch
     - Avoid schema completion after SET STATISTICS

I couldn't write patches details on previous email, so I write
more explanation for that on this email.


* tab_completion_alter_index_set_statistics.patch
=======
There are two problems. You can use these DDL before testing.
  #create table hoge (a integer, b integer);
  #create index ind_hoge on hoge (a, (a + b), (a * b));

  1) Can't get column names

    # alter index ind_hoge alter column <tab!><tab!>... but can't complete.

  2) I expected column names for column numbers after "SET STATISTICS", but
     tab-completion gave schema names

    # alter index ind_hoge alter column expr SET STATISTICS <tab!>
    information_schema.  pg_catalog.          pg_temp_1.           pg_toast.    
        pg_toast_temp_1.     public.

Applied the patch:

  1) We can get column names after "alter column".

    # alter index ind_hoge alter column <tab!>
    a      expr   expr1

  2) Fix!
    # alter index ind_hoge alter column expr SET STATISTICS <tab!>
=======


* fix_manual_of_alter_index_v2.patch (Attached on this email)
=======
https://www.postgresql.org/docs/devel/sql-alterindex.html

The patch fixes the syntax on above manual.
  s/column_number/column_number \| column_name/
And also it adds an explanation for column_name.

Syntax of ALTER INDEX ALTER COLUMN SET STATISTICS on the manual is below:

  ALTER INDEX [ IF EXISTS ] name ALTER [ COLUMN ] column_number
      SET STATISTICS integer

But we can use not only column number but also column name like this:

  # alter index ind_hoge alter column 2 SET STATISTICS 100;
  ALTER INDEX
  # alter index ind_hoge alter column expr SET STATISTICS 100;
  ALTER INDEX
=======


* tab_completion_alter_table_set_statistics.patch
=======
For now, we can get schema name by tab-completion. It is not appropriate.

  # alter table hoge alter column a set statistics <tab!>
  information_schema.  pg_catalog.          pg_temp_1.           pg_toast.      
      pg_toast_temp_1.     public.

Applied the patch:

  # alter table hoge alter column a set statistics <tab!>
=======

Any feedback is welcome. :)

Thanks,
Tatsuro Yamada
NTT Open Source Software Center
diff --git a/doc/src/sgml/ref/alter_index.sgml b/doc/src/sgml/ref/alter_index.sgml
index 6d34dbb74e..1b5b1f7ef1 100644
--- a/doc/src/sgml/ref/alter_index.sgml
+++ b/doc/src/sgml/ref/alter_index.sgml
@@ -27,7 +27,7 @@ ALTER INDEX <replaceable class="parameter">name</replaceable> ATTACH PARTITION <
 ALTER INDEX <replaceable class="parameter">name</replaceable> DEPENDS ON EXTENSION <replaceable class="parameter">extension_name</replaceable>
 ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">storage_parameter</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )
 ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET ( <replaceable class="parameter">storage_parameter</replaceable> [, ... ] )
-ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable>
+ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable> | <replaceable class="parameter">column_name</replaceable>
     SET STATISTICS <replaceable class="parameter">integer</replaceable>
 ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable> [ OWNED BY <replaceable class="parameter">role_name</replaceable> [, ... ] ]
     SET TABLESPACE <replaceable class="parameter">new_tablespace</replaceable> [ NOWAIT ]
@@ -137,14 +137,12 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
    </varlistentry>
 
    <varlistentry>
-    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable> SET STATISTICS <replaceable class="parameter">integer</replaceable></literal></term>
+    <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable> | <replaceable class="parameter">column_name</replaceable> SET STATISTICS <replaceable class="parameter">integer</replaceable></literal></term>
     <listitem>
      <para>
       This form sets the per-column statistics-gathering target for
       subsequent <xref linkend="sql-analyze"/> operations, though can
       be used only on index columns that are defined as an expression.
-      Since expressions lack a unique name, we refer to them using the
-      ordinal number of the index column.
       The target can be set in the range 0 to 10000; alternatively, set it
       to -1 to revert to using the system default statistics
       target (<xref linkend="guc-default-statistics-target"/>).
@@ -175,6 +173,15 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><replaceable class="parameter">column_name</replaceable></term>
+      <listitem>
+       <para>
+        The name of an existing index column.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><replaceable class="parameter">column_number</replaceable></term>
       <listitem>

Reply via email to