orms-opt.slt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/orms-opt
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. # not supported yet
  20. halt
  21. mode cockroach
  22. ## This test file contains various complex queries that ORMs issue during
  23. ## startup or general use, that pre-CBO code can't handle. This file should be
  24. ## merged with the orms test file once the heuristic planner is gone.
  25. statement ok
  26. CREATE TABLE a (a INT PRIMARY KEY)
  27. # ActiveRecord query that needs apply join.
  28. query TTTBTITT
  29. SELECT a.attname,
  30. format_type(a.atttypid, a.atttypmod),
  31. pg_get_expr(d.adbin, d.adrelid),
  32. a.attnotnull,
  33. a.atttypid,
  34. a.atttypmod,
  35. (SELECT c.collname
  36. FROM pg_collation c, pg_type t
  37. WHERE c.oid = a.attcollation
  38. AND t.oid = a.atttypid
  39. AND a.attcollation <> t.typcollation),
  40. col_description(a.attrelid, a.attnum) AS comment
  41. FROM pg_attribute a LEFT JOIN pg_attrdef d
  42. ON a.attrelid = d.adrelid AND a.attnum = d.adnum
  43. WHERE a.attrelid = '"a"'::regclass
  44. AND a.attnum > 0 AND NOT a.attisdropped
  45. ORDER BY a.attnum
  46. ----
  47. a bigint NULL true 20 -1 NULL NULL
  48. # Navicat metadata query.
  49. query TTBBB
  50. SELECT
  51. attname AS name,
  52. attrelid AS tid,
  53. COALESCE(
  54. (
  55. SELECT
  56. attnum = ANY conkey
  57. FROM
  58. pg_constraint
  59. WHERE
  60. contype = 'p' AND conrelid = attrelid
  61. ),
  62. false
  63. )
  64. AS primarykey,
  65. NOT (attnotnull) AS allownull,
  66. (
  67. SELECT
  68. seq.oid
  69. FROM
  70. pg_class AS seq
  71. LEFT JOIN pg_depend AS dep
  72. ON seq.oid = dep.objid
  73. WHERE
  74. (
  75. seq.relkind = 'S'::CHAR
  76. AND dep.refobjsubid = attnum
  77. )
  78. AND dep.refobjid = attrelid
  79. )
  80. IS NOT NULL
  81. AS autoincrement
  82. FROM
  83. pg_attribute
  84. WHERE
  85. (
  86. attisdropped = false
  87. AND attrelid
  88. = (
  89. SELECT
  90. tbl.oid
  91. FROM
  92. pg_class AS tbl
  93. LEFT JOIN pg_namespace AS sch
  94. ON tbl.relnamespace = sch.oid
  95. WHERE
  96. (
  97. tbl.relkind = 'r'::"char"
  98. AND tbl.relname = 'a'
  99. )
  100. AND sch.nspname = 'public'
  101. )
  102. )
  103. AND attname = 'a';
  104. ----
  105. a 53 true false false