DESCRIBE

功能描述

DESCRIBE 和 EXPLAIN 互为同义词,可以用于查看指定表结构,或查看指定 SQL 的执行计划。

查看执行计划部分内容详见 EXPLAIN

注意事项

  • 临时表需要指定临时表对应的schema查询。
  • 复合主键索引所有参与列都会在Key字段中显示为PRI。
  • 复合唯一索引所有参与列都会在Key字段中显示为UNI。
  • 如果一个列参与了多个索引的创建,将按 PRI、UNI、MUL 的优先级顺序显示。
  • 生成列会在Default中显示生成式。
  • 不支持表同义词。

语法格式

  1. {DESCRIBE | DESC | EXPLAIN} tbl_name

参数说明

  • {DESCRIBE | DESC | EXPLAIN}

    1. 使用 DESCRIBEDESC EXPLAIN 效果是等价的。
  • tbl_name

    1. 表名,可指定表名。也可以指定schema_name.table_name

示例

  1. --创建test
  2. openGauss=# CREATE TABLE test2
  3. openGauss-# (
  4. openGauss(# id int PRIMARY KEY
  5. openGauss(# );
  6. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test2_pkey" for table "test2"
  7. CREATE TABLE
  8. openGauss=# create table test
  9. openGauss-# (
  10. openGauss(# a SERIAL,
  11. openGauss(# b varchar(10),
  12. openGauss(# c varchar(10),
  13. openGauss(# d varchar(10),
  14. openGauss(# e varchar(10),
  15. openGauss(# f varchar(10),
  16. openGauss(# g varchar(10) DEFAULT 'g',
  17. openGauss(# h varchar(10) NOT NULL,
  18. openGauss(# i int DEFAULT 0,
  19. openGauss(# j int DEFAULT 0,
  20. openGauss(# k int GENERATED ALWAYS AS (i + j) STORED,
  21. openGauss(# l int DEFAULT 0,
  22. openGauss(# m int CHECK (m < 50),
  23. openGauss(# PRIMARY KEY (a, b),
  24. openGauss(# FOREIGN KEY(l) REFERENCES test2(id)
  25. openGauss(# );
  26. NOTICE: CREATE TABLE will create implicit sequence "test_a_seq" for serial column "test.a"
  27. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_pkey" for table "test"
  28. CREATE TABLE
  29. openGauss=# CREATE UNIQUE INDEX idx_c on test (c);
  30. CREATE INDEX
  31. openGauss=# CREATE UNIQUE INDEX idx_d_e on test (d, e);
  32. CREATE INDEX
  33. openGauss=# CREATE INDEX idx_f on test (f);
  34. CREATE INDEX
  35. --查看test表结构
  36. openGauss=# desc test;
  37. Field | Type | Null | Key | Default | Extra
  38. -------+-----------------------+------+-----+---------------------------------+-------
  39. a | integer | NO | PRI | nextval('test_a_seq'::regclass) |
  40. b | character varying(10) | NO | PRI | NULL |
  41. c | character varying(10) | YES | UNI | NULL |
  42. d | character varying(10) | YES | UNI | NULL |
  43. e | character varying(10) | YES | UNI | NULL |
  44. f | character varying(10) | YES | MUL | NULL |
  45. g | character varying(10) | YES | | 'g'::character varying |
  46. h | character varying(10) | NO | | NULL |
  47. i | integer | YES | | 0 |
  48. j | integer | YES | | 0 |
  49. k | integer | YES | | (i + j) |
  50. l | integer | YES | MUL | 0 |
  51. m | integer | YES | | NULL |
  52. (13 rows)
  53. openGauss=# desc public.test;
  54. Field | Type | Null | Key | Default | Extra
  55. -------+-----------------------+------+-----+---------------------------------+-------
  56. a | integer | NO | PRI | nextval('test_a_seq'::regclass) |
  57. b | character varying(10) | NO | PRI | NULL |
  58. c | character varying(10) | YES | UNI | NULL |
  59. d | character varying(10) | YES | UNI | NULL |
  60. e | character varying(10) | YES | UNI | NULL |
  61. f | character varying(10) | YES | MUL | NULL |
  62. g | character varying(10) | YES | | 'g'::character varying |
  63. h | character varying(10) | NO | | NULL |
  64. i | integer | YES | | 0 |
  65. j | integer | YES | | 0 |
  66. k | integer | YES | | (i + j) |
  67. l | integer | YES | MUL | 0 |
  68. m | integer | YES | | NULL |
  69. (13 rows)
  70. openGauss=# describe public.test;
  71. Field | Type | Null | Key | Default | Extra
  72. -------+-----------------------+------+-----+---------------------------------+-------
  73. a | integer | NO | PRI | nextval('test_a_seq'::regclass) |
  74. b | character varying(10) | NO | PRI | NULL |
  75. c | character varying(10) | YES | UNI | NULL |
  76. d | character varying(10) | YES | UNI | NULL |
  77. e | character varying(10) | YES | UNI | NULL |
  78. f | character varying(10) | YES | MUL | NULL |
  79. g | character varying(10) | YES | | 'g'::character varying |
  80. h | character varying(10) | NO | | NULL |
  81. i | integer | YES | | 0 |
  82. j | integer | YES | | 0 |
  83. k | integer | YES | | (i + j) |
  84. l | integer | YES | MUL | 0 |
  85. m | integer | YES | | NULL |
  86. (13 rows)

相关链接

EXPLAIN