large_tables.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. class WideRows(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE wide_rows (f1 TEXT);
  18. > CREATE DEFAULT INDEX ON wide_rows;
  19. > INSERT INTO wide_rows VALUES (REPEAT('a', 16 * 1024 * 1024));
  20. """
  21. )
  22. )
  23. def manipulate(self) -> list[Testdrive]:
  24. return [
  25. Testdrive(dedent(s))
  26. for s in [
  27. """
  28. > INSERT INTO wide_rows VALUES (REPEAT('b', 16 * 1024 * 1024));
  29. """,
  30. """
  31. > INSERT INTO wide_rows SELECT * FROM wide_rows;
  32. """,
  33. ]
  34. ]
  35. def validate(self) -> Testdrive:
  36. return Testdrive(
  37. dedent(
  38. """
  39. > SELECT LEFT(f1, 1), SUM(LENGTH(f1)) FROM wide_rows GROUP BY LEFT(f1, 1);
  40. a 33554432
  41. b 33554432
  42. """
  43. )
  44. )
  45. class ManyRows(Check):
  46. def initialize(self) -> Testdrive:
  47. return Testdrive(
  48. dedent(
  49. """
  50. > CREATE TABLE many_rows (f1 TEXT);
  51. > CREATE DEFAULT INDEX ON many_rows;
  52. > INSERT INTO many_rows SELECT 'a' || generate_series FROM generate_series(1, 1000000);
  53. """
  54. )
  55. )
  56. def manipulate(self) -> list[Testdrive]:
  57. return [
  58. Testdrive(dedent(s))
  59. for s in [
  60. """
  61. > INSERT INTO many_rows SELECT 'b' || generate_series FROM generate_series(1, 1000000);
  62. """,
  63. """
  64. > INSERT INTO many_rows SELECT * FROM many_rows;
  65. """,
  66. ]
  67. ]
  68. def validate(self) -> Testdrive:
  69. return Testdrive(
  70. dedent(
  71. """
  72. > SELECT LEFT(f1, 1), COUNT(f1) FROM many_rows GROUP BY LEFT(f1, 1);
  73. a 2000000
  74. b 2000000
  75. """
  76. )
  77. )