negative-multiplicities.td 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  10. ALTER SYSTEM SET enable_repeat_row = true
  11. > CREATE TABLE base (data bigint, unsigned_data uint4, diff bigint)
  12. > CREATE MATERIALIZED VIEW data AS SELECT data, unsigned_data FROM base, repeat_row(diff)
  13. > INSERT INTO base VALUES (1, 1, 1)
  14. > SELECT * FROM data
  15. 1 1
  16. > INSERT INTO base VALUES (1, 1, -1), (1, 1, -1)
  17. > SELECT count(*) FROM data
  18. -1
  19. ! SELECT * FROM data
  20. contains:Invalid data in source, saw retractions (1) for row that does not exist: [Int64(1), UInt32(1)]
  21. > INSERT INTO base VALUES (1, 1, -1)
  22. > SELECT count(*) FROM data
  23. -2
  24. ! SELECT * FROM data
  25. contains:Invalid data in source, saw retractions (2) for row that does not exist: [Int64(1), UInt32(1)]
  26. # regression scenario per database-issues#5246, with non-monotonic rendering
  27. > CREATE VIEW topk AS
  28. SELECT grp.id, count(t.data) AS top_2_count,
  29. (SELECT COUNT(d.data) FROM data d WHERE d.data % 2 = grp.id) AS total_count
  30. FROM (SELECT generate_series(0,1) id) grp,
  31. LATERAL (SELECT data FROM data WHERE data % 2 = grp.id ORDER BY data LIMIT 2) t
  32. GROUP BY grp.id;
  33. > CREATE DEFAULT INDEX ON topk;
  34. ! SELECT * from topk;
  35. contains:Negative multiplicities in TopK
  36. # regression scenario per database-issues#5224
  37. ! SELECT DISTINCT data FROM data;
  38. contains:Non-positive multiplicity in DistinctBy
  39. # regression scenario per database-issues#5359
  40. ! SELECT list_agg(DISTINCT data)[1] FROM data;
  41. contains:Non-positive accumulation in ReduceInaccumulable DISTINCT
  42. # regression scenario per database-issues#5360
  43. ! SELECT list_agg(data)[1] FROM data;
  44. contains:Non-positive accumulation in ReduceInaccumulable
  45. # regression scenario per database-issues#5086, with non-monotonic rendering
  46. > CREATE VIEW max_data AS
  47. SELECT MAX(data) FROM data;
  48. > CREATE DEFAULT INDEX ON max_data;
  49. ! SELECT * FROM max_data;
  50. contains:Invalid data in source, saw non-positive accumulation
  51. # verify that some reduction in a collation plan catches a negative
  52. # multiplicity.
  53. > CREATE VIEW collation AS
  54. SELECT
  55. data,
  56. COUNT(DISTINCT data),
  57. STRING_AGG(data::text || '1', ',') AS data_1,
  58. MIN(data),
  59. MAX(DISTINCT data),
  60. SUM(data),
  61. STRING_AGG(data::text || '2', ',') AS data_2
  62. FROM data
  63. GROUP BY data;
  64. > CREATE DEFAULT INDEX ON collation;
  65. ! SELECT * FROM collation;
  66. # Case-insensitive match for both 'Non' and 'non'
  67. contains:on-positive accumulation
  68. # Window aggregations
  69. # These are currently commented out, because window functions currently don't check their inputs for negative
  70. # multiplicities, see https://github.com/MaterializeInc/database-issues/issues/8568
  71. #! SELECT list_agg(data) OVER ()[1] FROM data;
  72. #contains:Non-positive accumulation in ReduceInaccumulable
  73. #! SELECT sum(data) OVER () FROM data;
  74. #contains:Non-positive accumulation in ReduceInaccumulable
  75. #! SELECT max(data) OVER () FROM data;
  76. #contains:Non-positive accumulation in ReduceInaccumulable
  77. #! SELECT list_agg(unsigned_data) OVER ()[1] FROM data;
  78. #contains:Non-positive accumulation in ReduceInaccumulable
  79. #! SELECT sum(unsigned_data) OVER () FROM data;
  80. #contains:Non-positive accumulation in ReduceInaccumulable
  81. #! SELECT max(unsigned_data) OVER () FROM data;
  82. #contains:Non-positive accumulation in ReduceInaccumulable