On Mon, Mar 24, 2014 at 01:35:20PM -0300, Alvaro Herrera wrote:
> Bruce Momjian wrote:
> > On Mon, Mar 24, 2014 at 05:06:25PM +0100, Andres Freund wrote:
> > > On 2014-03-22 23:47:57 -0400, Bruce Momjian wrote:
> > > >         test=> \d+ test
> > > >                                  Table "public.test"
> > > >          Column |  Type   | Modifiers | Storage | Stats target | 
> > > > Description
> > > >         
> > > > --------+---------+-----------+---------+--------------+-------------
> > > >          x      | integer |           | plain   |              |
> > > >         Replica Identity: full
> > > >         Has OIDs: no
> > > > 
> > > > I used lower-case for the value, rather than all-caps.
> > > 
> > > Why? CLUSTER, PRIMARY KEY, etc. are displayed all caps, and replica
> > > identity is similarly set via ALTER TABLE ... REPLICA IDENITY?
> > 
> > Oh, good points;  I had not considered PRIMARY KEY.  Updated patch
> > attached.
> 
> In the "INDEX" case, should the output mention specifically which index
> is being considered?

Ah, good idea.  Updated patch attached.  The output is now:

        test=> \d+ test
                                 Table "public.test"
         Column |  Type   | Modifiers | Storage | Stats target | Description
        --------+---------+-----------+---------+--------------+-------------
         x      | integer | not null  | plain   |              |
        Indexes:
            "test_pkey" PRIMARY KEY, btree (x) REPLICA IDENTITY
            "i_test2" btree (x)
-->     Replica Identity: USING INDEX "test_pkey"
        Has OIDs: no

However, now that I look at it, it seems redundant as REPLICA IDENTITY
is already marked on the actual index.  Ideas?

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
new file mode 100644
index a194ce7..2230968
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
*************** describeOneTableDetails(const char *sche
*** 2345,2358 ****
  			printTableAddFooter(&cont, buf.data);
  		}
  
! 		if ((tableinfo.relkind == 'r' || tableinfo.relkind == 'm') &&
! 			tableinfo.relreplident != 'd' && tableinfo.relreplident != 'i')
  		{
  			const char *s = _("Replica Identity");
  
! 			printfPQExpBuffer(&buf, "%s: %s",
! 							  s,
! 							  tableinfo.relreplident == 'n' ? "NOTHING" : "FULL");
  			printTableAddFooter(&cont, buf.data);
  		}
  
--- 2345,2387 ----
  			printTableAddFooter(&cont, buf.data);
  		}
  
! 		if (verbose && (tableinfo.relkind == 'r' || tableinfo.relkind == 'm') &&
! 			strcmp(schemaname, "pg_catalog") != 0)
  		{
  			const char *s = _("Replica Identity");
  
! 			/* find USING INDEX index? */
! 			if (tableinfo.relreplident == 'i')
! 			{
! 				printfPQExpBuffer(&buf,
! 								  "SELECT r.relname\n"
! 								  "FROM pg_catalog.pg_class r,\n"
! 								  "     pg_catalog.pg_index i\n"
! 								  "WHERE i.indrelid = %s AND "
! 								  "      i.indisreplident AND "
! 								  "      i.indexrelid = r.oid;",
! 								  oid);
! 				result = PSQLexec(buf.data, false);
! 				if (!result)
! 					goto error_return;
! 				else if (PQntuples(result) != 1)
! 				{
! 					PQclear(result);
! 					goto error_return;
! 				}
! 	
! 				printfPQExpBuffer(&buf, _("%s: USING INDEX \"%s\""), s,
! 								  PQgetvalue(result, 0, 0));
! 				PQclear(result);
! 			}
! 			else
! 				printfPQExpBuffer(&buf, "%s: %s",
! 								  s,
! 								  tableinfo.relreplident == 'd' ? "DEFAULT" :
! 								  tableinfo.relreplident == 'f' ? "FULL" :
! 								  tableinfo.relreplident == 'n' ? "NOTHING" :
! 								  "???");
! 
  			printTableAddFooter(&cont, buf.data);
  		}
  
diff --git a/src/test/regress/expected/create_table_like.out b/src/test/regress/expected/create_table_like.out
new file mode 100644
index 5f29b39..feb6c93
*** a/src/test/regress/expected/create_table_like.out
--- b/src/test/regress/expected/create_table_like.out
*************** CREATE TABLE ctlt12_storage (LIKE ctlt1
*** 115,120 ****
--- 115,121 ----
   a      | text | not null  | main     |              | 
   b      | text |           | extended |              | 
   c      | text |           | external |              | 
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 INCLUDING COMMENTS);
*************** CREATE TABLE ctlt12_comments (LIKE ctlt1
*** 125,130 ****
--- 126,132 ----
   a      | text | not null  | extended |              | A
   b      | text |           | extended |              | B
   c      | text |           | extended |              | C
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) INHERITS (ctlt1);
*************** NOTICE:  merging constraint "ctlt1_a_che
*** 140,145 ****
--- 142,148 ----
  Check constraints:
      "ctlt1_a_check" CHECK (length(a) > 2)
  Inherits: ctlt1
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt1_inh'::regclass;
*************** Check constraints:
*** 162,167 ****
--- 165,171 ----
      "ctlt3_a_check" CHECK (length(a) < 5)
  Inherits: ctlt1,
            ctlt3
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  CREATE TABLE ctlt13_like (LIKE ctlt3 INCLUDING CONSTRAINTS INCLUDING COMMENTS INCLUDING STORAGE) INHERITS (ctlt1);
*************** Check constraints:
*** 177,182 ****
--- 181,187 ----
      "ctlt1_a_check" CHECK (length(a) > 2)
      "ctlt3_a_check" CHECK (length(a) < 5)
  Inherits: ctlt1
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt13_like'::regclass;
*************** Indexes:
*** 198,203 ****
--- 203,209 ----
      "ctlt_all_expr_idx" btree ((a || b))
  Check constraints:
      "ctlt1_a_check" CHECK (length(a) > 2)
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid;
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
new file mode 100644
index c84c435..7f2eeea
*** a/src/test/regress/expected/inherit.out
--- b/src/test/regress/expected/inherit.out
*************** ALTER TABLE inhts RENAME d TO dd;
*** 913,918 ****
--- 913,919 ----
   dd     | integer |           | plain   |              | 
  Inherits: inht1,
            inhs1
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  DROP TABLE inhts;
*************** ALTER TABLE inht1 RENAME aa TO aaa;
*** 934,939 ****
--- 935,941 ----
   z      | integer |           | plain   |              | 
  Inherits: inht2,
            inht3
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  CREATE TABLE inhts (d int) INHERITS (inht2, inhs1);
*************** ERROR:  cannot rename inherited column "
*** 952,957 ****
--- 954,960 ----
   d      | integer |           | plain   |              | 
  Inherits: inht2,
            inhs1
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  WITH RECURSIVE r AS (
*************** CREATE TABLE test_constraints_inh () INH
*** 999,1004 ****
--- 1002,1008 ----
  Indexes:
      "test_constraints_val1_val2_key" UNIQUE CONSTRAINT, btree (val1, val2)
  Child tables: test_constraints_inh
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  ALTER TABLE ONLY test_constraints DROP CONSTRAINT test_constraints_val1_val2_key;
*************** ALTER TABLE ONLY test_constraints DROP C
*** 1010,1015 ****
--- 1014,1020 ----
   val1   | character varying |           | extended |              | 
   val2   | integer           |           | plain    |              | 
  Child tables: test_constraints_inh
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  \d+ test_constraints_inh
*************** Has OIDs: no
*** 1020,1025 ****
--- 1025,1031 ----
   val1   | character varying |           | extended |              | 
   val2   | integer           |           | plain    |              | 
  Inherits: test_constraints
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  DROP TABLE test_constraints_inh;
*************** CREATE TABLE test_ex_constraints_inh ()
*** 1037,1042 ****
--- 1043,1049 ----
  Indexes:
      "test_ex_constraints_c_excl" EXCLUDE USING gist (c WITH &&)
  Child tables: test_ex_constraints_inh
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  ALTER TABLE test_ex_constraints DROP CONSTRAINT test_ex_constraints_c_excl;
*************** ALTER TABLE test_ex_constraints DROP CON
*** 1046,1051 ****
--- 1053,1059 ----
  --------+--------+-----------+---------+--------------+-------------
   c      | circle |           | plain   |              | 
  Child tables: test_ex_constraints_inh
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  \d+ test_ex_constraints_inh
*************** Has OIDs: no
*** 1054,1059 ****
--- 1062,1068 ----
  --------+--------+-----------+---------+--------------+-------------
   c      | circle |           | plain   |              | 
  Inherits: test_ex_constraints
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  DROP TABLE test_ex_constraints_inh;
*************** Indexes:
*** 1071,1076 ****
--- 1080,1086 ----
      "test_primary_constraints_pkey" PRIMARY KEY, btree (id)
  Referenced by:
      TABLE "test_foreign_constraints" CONSTRAINT "test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  \d+ test_foreign_constraints
*************** Has OIDs: no
*** 1081,1086 ****
--- 1091,1097 ----
  Foreign-key constraints:
      "test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
  Child tables: test_foreign_constraints_inh
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id1_fkey;
*************** ALTER TABLE test_foreign_constraints DRO
*** 1090,1095 ****
--- 1101,1107 ----
  --------+---------+-----------+---------+--------------+-------------
   id1    | integer |           | plain   |              | 
  Child tables: test_foreign_constraints_inh
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  \d+ test_foreign_constraints_inh
*************** Has OIDs: no
*** 1098,1103 ****
--- 1110,1116 ----
  --------+---------+-----------+---------+--------------+-------------
   id1    | integer |           | plain   |              | 
  Inherits: test_foreign_constraints
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  DROP TABLE test_foreign_constraints_inh;
diff --git a/src/test/regress/expected/matview.out b/src/test/regress/expected/matview.out
new file mode 100644
index daf3b9e..37db38d
*** a/src/test/regress/expected/matview.out
--- b/src/test/regress/expected/matview.out
*************** View definition:
*** 104,109 ****
--- 104,110 ----
      tv.totamt
     FROM tv
    ORDER BY tv.type;
+ Replica Identity: DEFAULT
  
  \d+ tvm
                      Materialized view "public.tvm"
*************** View definition:
*** 116,121 ****
--- 117,123 ----
      tv.totamt
     FROM tv
    ORDER BY tv.type;
+ Replica Identity: DEFAULT
  
  \d+ tvvm
                      Materialized view "public.tvvm"
*************** View definition:
*** 125,130 ****
--- 127,133 ----
  View definition:
   SELECT tvv.grandtot
     FROM tvv;
+ Replica Identity: DEFAULT
  
  \d+ bb
                       Materialized view "public.bb"
*************** Indexes:
*** 136,141 ****
--- 139,145 ----
  View definition:
   SELECT tvvmv.grandtot
     FROM tvvmv;
+ Replica Identity: DEFAULT
  
  -- test schema behavior
  CREATE SCHEMA mvschema;
*************** Indexes:
*** 152,157 ****
--- 156,162 ----
  View definition:
   SELECT sum(tvm.totamt) AS grandtot
     FROM mvschema.tvm;
+ Replica Identity: DEFAULT
  
  SET search_path = mvschema, public;
  \d+ tvm
*************** View definition:
*** 165,170 ****
--- 170,176 ----
      tv.totamt
     FROM tv
    ORDER BY tv.type;
+ Replica Identity: DEFAULT
  
  -- modify the underlying table data
  INSERT INTO t VALUES (6, 'z', 13);
*************** UNION ALL
*** 369,374 ****
--- 375,381 ----
           SELECT v_test2.moo,
              3 * v_test2.moo
             FROM v_test2;
+ Replica Identity: DEFAULT
  
  CREATE MATERIALIZED VIEW mv_test3 AS SELECT * FROM mv_test2 WHERE moo = 12345;
  SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass;
diff --git a/src/test/regress/expected/replica_identity.out b/src/test/regress/expected/replica_identity.out
new file mode 100644
index a93897f..aeaf0fb
*** a/src/test/regress/expected/replica_identity.out
--- b/src/test/regress/expected/replica_identity.out
*************** Indexes:
*** 170,176 ****
      "test_replica_identity_unique_nondefer" UNIQUE CONSTRAINT, btree (keya, keyb)
      "test_replica_identity_hash" hash (nonkey)
      "test_replica_identity_keyab" btree (keya, keyb)
- Replica Identity: FULL
  
  ALTER TABLE test_replica_identity REPLICA IDENTITY NOTHING;
  SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
--- 170,175 ----
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
new file mode 100644
index b0b6e27..25a36f4
*** a/src/test/regress/expected/rules.out
--- b/src/test/regress/expected/rules.out
*************** Rules:
*** 2609,2614 ****
--- 2609,2615 ----
      r3 AS
      ON DELETE TO rules_src DO
   NOTIFY rules_src_deletion
+ Replica Identity: DEFAULT
  Has OIDs: no
  
  --
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to