/** Bad */
\timing

/** Create GiST index and populate */
CREATE TABLE logs2_gist (
    id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    log_time tstzrange NOT NULL
);
CREATE INDEX logs2_log_time_gist_idx ON logs2_gist USING gist(log_time);

INSERT INTO logs2_gist (log_time)
SELECT
    tstzrange(
        y.start_time + (x || 'days')::interval,
        y.end_time + (x || 'days')::interval
    )
FROM generate_series(1, 400000) x,
    LATERAL (
        SELECT z.*
        FROM (
            VALUES
                ('2003-04-01 9:00'::timestamptz, '2003-04-01 12:30'::timestamptz),
                ('2003-04-01 14:00'::timestamptz, '2003-04-01 16:30'::timestamptz),
                ('2003-04-01 19:30'::timestamptz, '2003-04-01 21:00'::timestamptz)

        ) z(start_time, end_time)
    ) y;

/** Create SP-GiST index and populate */
CREATE TABLE logs2_spgist (
    id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    log_time tstzrange NOT NULL
);
CREATE INDEX logs2_log_time_spgist_idx ON logs2_spgist USING spgist(log_time);

INSERT INTO logs2_spgist (log_time)
SELECT
    tstzrange(
        y.start_time + (x || 'days')::interval,
        y.end_time + (x || 'days')::interval
    )
FROM generate_series(1, 400000) x,
    LATERAL (
        SELECT z.*
        FROM (
            VALUES
                ('2003-04-01 9:00'::timestamptz, '2003-04-01 12:30'::timestamptz),
                ('2003-04-01 14:00'::timestamptz, '2003-04-01 16:30'::timestamptz),
                ('2003-04-01 19:30'::timestamptz, '2003-04-01 21:00'::timestamptz)

        ) z(start_time, end_time)
    ) y;
