Skip to content

Commit

Permalink
[pg15] test: re-port regress misc, misc_functions, prepare
Browse files Browse the repository at this point in the history
Summary:
Re-port pg_regress tests misc, misc_functions, and prepare.  These tests
originally exist in yb_pg_misc_independent_serial_schedule, but since
they now rely on test_setup, move them to yb_pg_misc_serial_schedule.

Test Plan:
On Almalinux 8:

    #!/usr/bin/env bash
    set -eu
    ./yb_build.sh fastdebug --gcc11
    yes "$(grep TestPgRegressPgMisc pg15_tests/passing_tests.tsv)" | head -50 | pg15_tests/run_tests.sh

Jenkins: rebase: pg15, test regex: TestPgRegressPgMisc

Reviewers: fizaa, tfoucher

Reviewed By: tfoucher

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D35797
  • Loading branch information
jaki committed Jun 13, 2024
1 parent a7aeefb commit 3fe5161
Show file tree
Hide file tree
Showing 8 changed files with 1,233 additions and 39 deletions.
228 changes: 221 additions & 7 deletions src/postgres/src/test/regress/expected/yb_pg_misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,85 @@
\getenv libdir PG_LIBDIR
\getenv dlsuffix PG_DLSUFFIX
\set regresslib :libdir '/regress' :dlsuffix
-- TODO requires 'INHERITS' which is not supported.
CREATE FUNCTION overpaid(emp)
RETURNS bool
AS :'regresslib'
LANGUAGE C STRICT;
LANGUAGE C STRICT; -- YB: fails because creating emp requires unsupported INHERITS
ERROR: type emp does not exist
CREATE FUNCTION reverse_name(name)
RETURNS name
AS :'regresslib'
LANGUAGE C STRICT;
--
-- BTREE
--
UPDATE onek
SET unique1 = onek.unique1 + 1;
UPDATE onek
SET unique1 = onek.unique1 - 1;
--
-- BTREE partial
--
-- UPDATE onek2
-- SET unique1 = onek2.unique1 + 1;
--UPDATE onek2
-- SET unique1 = onek2.unique1 - 1;
--
-- BTREE shutting out non-functional updates
--
-- the following two tests seem to take a long time on some
-- systems. This non-func update stuff needs to be examined
-- more closely. - jolly (2/22/96)
--
SELECT two, stringu1, ten, string4
INTO TABLE tmp
FROM onek;
UPDATE tmp
SET stringu1 = reverse_name(onek.stringu1)
FROM onek
WHERE onek.stringu1 = 'JBAAAA' and
onek.stringu1 = tmp.stringu1;
UPDATE tmp
SET stringu1 = reverse_name(onek2.stringu1)
FROM onek2
WHERE onek2.stringu1 = 'JCAAAA' and
onek2.stringu1 = tmp.stringu1;
DROP TABLE tmp;
--UPDATE person*
-- SET age = age + 1;
--UPDATE person*
-- SET age = age + 3
-- WHERE name = 'linda';
--
-- copy
--
\set filename :abs_builddir '/results/onek.data'
COPY onek TO :'filename';
-- YB note: create YB table instead of temp table to exercise YB tables.
CREATE TABLE onek_copy (LIKE onek);
CREATE TABLE onek_copy (LIKE onek); -- YB: create YB table instead of temp table to exercise YB tables
COPY onek_copy FROM :'filename';
SELECT * FROM onek EXCEPT ALL SELECT * FROM onek_copy;
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
(0 rows)

SELECT * FROM onek_copy EXCEPT ALL SELECT * FROM onek;
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
(0 rows)

\set filename :abs_builddir '/results/stud_emp.data'
COPY BINARY stud_emp TO :'filename';
ERROR: relation "stud_emp" does not exist
/* YB: uncomment when stud_emp is available (needs INHERITS)
CREATE TEMP TABLE stud_emp_copy (LIKE stud_emp);

COPY BINARY stud_emp_copy FROM :'filename';

SELECT * FROM stud_emp_copy;
*/ -- YB
--
-- test data for postquel functions
--
CREATE TABLE hobbies_r (
name text,
person text
Expand All @@ -33,6 +94,22 @@ CREATE TABLE equipment_r (
name text,
hobby text
);
INSERT INTO hobbies_r (name, person)
SELECT 'posthacking', p.name
FROM person* p
WHERE p.name = 'mike' or p.name = 'jeff';
INSERT INTO hobbies_r (name, person)
SELECT 'basketball', p.name
FROM person p
WHERE p.name = 'joe' or p.name = 'sally';
INSERT INTO hobbies_r (name) VALUES ('skywalking');
INSERT INTO equipment_r (name, hobby) VALUES ('advil', 'posthacking');
INSERT INTO equipment_r (name, hobby) VALUES ('peet''s coffee', 'posthacking');
INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
--
-- postquel functions
--
CREATE FUNCTION hobbies(person)
RETURNS setof hobbies_r
AS 'select * from hobbies_r where person = $1.name'
Expand Down Expand Up @@ -79,6 +156,143 @@ CREATE FUNCTION equipment_named_ambiguous_2b(hobby text)
RETURNS setof equipment_r
AS 'select * from equipment_r where equipment_r.hobby = hobby'
LANGUAGE SQL;
-- YB note: mimic natural discard of temp tables for tables that have been
-- converted from temp tables in the upstream PG to YB tables here.
DROP TABLE onek_copy;
--
-- mike does post_hacking,
-- joe and sally play basketball, and
-- everyone else does nothing.
--
SELECT p.name, name(p.hobbies) FROM ONLY person p ORDER BY 2 DESC, 1; -- YB: add ordering
name | name
-------+-------------
mike | posthacking
joe | basketball
sally | basketball
(3 rows)

/* YB: uncomment when person's descendant tables such as stud_emp are supported
--
-- as above, but jeff also does post_hacking.
--
SELECT p.name, name(p.hobbies) FROM person* p;

--
-- the next two queries demonstrate how functions generate bogus duplicates.
-- this is a "feature" ..
--
SELECT DISTINCT hobbies_r.name, name(hobbies_r.equipment) FROM hobbies_r
ORDER BY 1,2;

SELECT hobbies_r.name, (hobbies_r.equipment).name FROM hobbies_r;

--
-- mike needs advil and peet's coffee,
-- joe and sally need hightops, and
-- everyone else is fine.
--
SELECT p.name, name(p.hobbies), name(equipment(p.hobbies)) FROM ONLY person p;

--
-- as above, but jeff needs advil and peet's coffee as well.
--
SELECT p.name, name(p.hobbies), name(equipment(p.hobbies)) FROM person* p;

--
-- just like the last two, but make sure that the target list fixup and
-- unflattening is being done correctly.
--
SELECT name(equipment(p.hobbies)), p.name, name(p.hobbies) FROM ONLY person p;

SELECT (p.hobbies).equipment.name, p.name, name(p.hobbies) FROM person* p;

SELECT (p.hobbies).equipment.name, name(p.hobbies), p.name FROM ONLY person p;

SELECT name(equipment(p.hobbies)), name(p.hobbies), p.name FROM person* p;
*/ -- YB
SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer')));
name
------
guts
(1 row)

SELECT name(equipment(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)

SELECT name(equipment_named(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)

SELECT name(equipment_named_ambiguous_1a(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)

SELECT name(equipment_named_ambiguous_1b(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)

SELECT name(equipment_named_ambiguous_1c(hobby_construct_named(text 'skywalking', text 'mer')));
name
------
guts
(1 row)

SELECT name(equipment_named_ambiguous_2a(text 'skywalking'));
name
------
guts
(1 row)

SELECT name(equipment_named_ambiguous_2b(text 'skywalking')) ORDER BY substr(name(equipment_named_ambiguous_2b(text 'skywalking')), 2, 1); -- YB: add ordering
name
---------------
advil
peet's coffee
hightops
guts
(4 rows)

/* YB: output sometimes gives joe, sometimes sally
SELECT hobbies_by_name('basketball');
*/ -- YB
SELECT name, overpaid(emp.*) FROM emp;
ERROR: relation "emp" does not exist
LINE 4: SELECT name, overpaid(emp.*) FROM emp;
^
--
-- Try a few cases with SQL-spec row constructor expressions
--
SELECT * FROM equipment(ROW('skywalking', 'mer'));
name | hobby
------+------------
guts | skywalking
(1 row)

SELECT name(equipment(ROW('skywalking', 'mer')));
name
------
guts
(1 row)

/* YB: uncomment when person's descendant tables such as stud_emp are supported
SELECT *, name(equipment(h.*)) FROM hobbies_r h;

SELECT *, (equipment(CAST((h.*) AS hobbies_r))).name FROM hobbies_r h;
*/ -- YB
--
-- functional joins
--
--
-- instance rules
--
--
-- rewrite rules
--
DROP TABLE onek_copy; -- YB: mimic natural discard of temp tables for tables that have been converted from temp tables in the upstream PG to YB tables here
Loading

0 comments on commit 3fe5161

Please sign in to comment.