# Check that all native types as well as some datum-backed types can be read
# correctly.
statement ok
CREATE TABLE all_types (
    _bool        BOOL,
    _bytes       BYTES,
    _date        DATE,
    _decimal     DECIMAL,
    _int2        INT2,
    _int4        INT4,
    _int         INT8,
    _oid         OID,
    _float       FLOAT8,
    _string      STRING,
    _uuid        UUID,
    _timestamp   TIMESTAMP,
    _timestamptz TIMESTAMPTZ,
    _interval    INTERVAL,
    _inet        INet,
    _json        JSON
)

statement ok
INSERT
  INTO all_types
VALUES (
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL
       ),
       (
       false,
       '123',
       '2019-10-22',
       1.23,
       123,
       123,
       123,
       123,
       1.23,
       '123',
       '63616665-6630-3064-6465-616462656562',
       '2001-1-18 1:00:00.001',
       '2001-1-18 1:00:00.001-8',
       '12:34:56.123456',
       '127.0.0.1',
       '[1, "hello", {"a": ["foo", {"b": 3}]}]'
       )

query BTTRIIIORTTTTTTT
SELECT * FROM all_types ORDER BY 1
----
NULL   NULL  NULL                             NULL  NULL  NULL  NULL  NULL  NULL  NULL  NULL                                  NULL                                 NULL                               NULL             NULL       NULL
false  123   2019-10-22 00:00:00 +0000 +0000  1.23  123   123   123   123   1.23  123   63616665-6630-3064-6465-616462656562  2001-01-18 01:00:00.001 +0000 +0000  2001-01-18 09:00:00.001 +0000 UTC  12:34:56.123456  127.0.0.1  [1, "hello", {"a": ["foo", {"b": 3}]}]

# Regression test for #44904 (mismatched physical types between materializer's
# input and output, root of the problem is outside of the vectorized engine).
# We should fallback to the row-by-row engine.
statement ok
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET default_int_size = 4;
CREATE TABLE t44904(c0 INT);
INSERT INTO t44904 VALUES(0);
COMMIT

query I
SELECT CAST(0 BETWEEN(CASE NULL WHEN c0 = 0 THEN NULL END) AND 0 IS TRUE AS INT) FROM t44904
----
0

# Regression test for #45038 (mismatched physical types between expected and
# actual physical types when wrapping unsupported processor cores).
statement ok
CREATE TABLE t45038(c0 INT); INSERT INTO t45038 VALUES(NULL)

query R
SELECT sum(c) FROM (SELECT CAST((IF(IF(false, false, c0 IS NULL), NULL, NULL)) BETWEEN 0 AND 0 IS TRUE AS INT) c FROM t45038)
----
0

statement ok
RESET default_int_size

# Regression test for #46714 (mismatched expected logical and actual physical
# integer types "inside" of the vectorized flow).
statement ok
CREATE TABLE t46714_0(c0 INT4); CREATE TABLE t46714_1(c0 INT4); INSERT INTO t46714_0 VALUES (0); INSERT INTO t46714_1 VALUES (0)

query I
SELECT 1 FROM t46714_0, t46714_1 GROUP BY t46714_0.c0 * t46714_1.c0
----
1

query I
SELECT * FROM t46714_0 ORDER BY c0 + c0
----
0

# Regression test for #47131 (mismatched expected logical and actual physical
# integer types on mixed-width integer binary expressions).
statement ok
CREATE TABLE t47131_0(c0 INT2 UNIQUE); INSERT INTO t47131_0 VALUES(1)

query I
SELECT * FROM t47131_0 WHERE (t47131_0.c0 + t47131_0.c0::INT4) = 0
----

query T
SELECT 'a'::"char" FROM t47131_0
----
a

# Regression test for the cFetcher not setting the not-needed columns to all
# nulls in some cases (#64676).
statement ok
CREATE TABLE t64676 (
  i INT,
  d DATE,
  u UUID
);
INSERT INTO t64676 VALUES
  (1, '2021-05-05', '00000000-0000-0000-0000-100000000000'),
  (2, '2021-05-05', '00000000-0000-0000-0000-200000000000'),
  (3, '2021-05-05', '00000000-0000-0000-0000-300000000000'),
  (4, '2021-05-05', '00000000-0000-0000-0000-400000000000'),
  (5, '2021-05-05', '00000000-0000-0000-0000-500000000000')

statement ok
SELECT i + d FROM t64676

# Regression test for type schema corruption when planning filter expressions
# (#107615).
statement ok
CREATE TABLE t107615 AS
	SELECT
		g::INT2 AS _int2,
		g::INT4 AS _int4,
		g::INT8 AS _int8,
		g::FLOAT8 AS _float8,
		'2001-01-01'::DATE + g AS _date,
		'2001-01-01'::TIMESTAMP + g * '1 day'::INTERVAL AS _timestamp,
		'2001-01-01'::TIMESTAMPTZ + g * '1 day'::INTERVAL AS _timestamptz,
		g * '1 day'::INTERVAL AS _interval,
		g % 2 = 1 AS _bool,
		g::DECIMAL AS _decimal,
		g::STRING AS _string,
		g::STRING::BYTES AS _bytes,
		substring('00000000-0000-0000-0000-' || g::STRING || '00000000000', 1, 36)::UUID AS _uuid
	FROM
		generate_series(1, 5) AS g;
SET testing_optimizer_random_seed = 4478711114964600496;
SELECT
	1.2345678901234564e+23:::FLOAT8,
	_string,
	_int2,
	tableoid,
	_int2,
	'1942-08-15 21:13:20+00':::TIMESTAMPTZ,
	'\xc3a0':::BYTES,
	true,
	_timestamp,
	_date,
	e'\x01':::STRING,
    _uuid,
	'{"test": "json"}':::JSONB,
	_int4,
	_interval
FROM
	t107615
WHERE
	(_bool OR (NOT _bool));

# Regression test for corrupting the column type schema captured by a vectorized
# operator due to sharing the same type slice by multiple stages of processors
# during physical planning (#130402).
statement ok
CREATE TABLE abcdef (
  a STRING,
  b INT4,
  c INT4,
  d INT4,
  e STRING,
  f STRING
);
INSERT INTO abcdef (a, b, c, d, e, f) VALUES ('a', 0, 0, 0, 'e', 'f');
CREATE TABLE ghijkl (
  g INT4,
  h INT4,
  i BOOL,
  j INT4,
  k STRING,
  l STRING
);
INSERT INTO ghijkl (g, h, i, j, k, l) VALUES (0, 0, true, -1, 'k', 'l');
SELECT c7, c1 >= (SELECT c FROM abcdef WHERE e != c3), c5
FROM (
  SELECT
    generate_series(g, d) AS c0,
    h AS c1,
    l AS c3,
    k AS c5,
    c AS c7
  FROM ghijkl
  LEFT JOIN abcdef ON b > j OR i NOT IN (e NOT IN (f, a),)
  LIMIT 2
)
WHERE c0 NOT IN (SELECT NULL FROM ghijkl);
