11-- create on perf_tests database
22
3-
4- create function perf_test (
3+ create or replace function perf_test (
54 _records int ,
65 _text_param text ,
76 _int_param int ,
@@ -23,20 +22,20 @@ returns table(
2322language sql
2423as
2524$$
26- select
27- i + _int_param as id1,
28- ' foo' || ' _' || _text_param || ' _' || i::text as foo1,
29- ' bar' || i::text as bar1,
30- (_ts_param::date ) + (i::text || ' days' )::interval as datetime1,
31- i+ 1 + _int_param as id2,
32- ' foo' || ' _' || _text_param || ' _' || (i+ 1 )::text as foo2,
33- ' bar' || ' _' || _text_param || ' _' || (i+ 1 )::text as bar2,
34- (_ts_param::date ) + ((i+ 1 )::text || ' days' )::interval as datetime2,
25+ select
26+ i + _int_param as id1,
27+ ' foo' || ' _' || _text_param || ' _' || i::text as foo1,
28+ ' bar' || i::text as bar1,
29+ (_ts_param::date ) + (i::text || ' days' )::interval as datetime1,
30+ i+ 1 + _int_param as id2,
31+ ' foo' || ' _' || _text_param || ' _' || (i+ 1 )::text as foo2,
32+ ' bar' || ' _' || _text_param || ' _' || (i+ 1 )::text as bar2,
33+ (_ts_param::date ) + ((i+ 1 )::text || ' days' )::interval as datetime2,
3534 ' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 2 )::text as long_foo_bar,
3635 (i % 2 )::boolean and _bool_param as is_foobar
37- from
36+ from
3837 generate_series(1 , _records) as i
39- $$;
38+ $$;
4039/*
4140select * from perf_test(
4241 _records => 10,
@@ -46,3 +45,119 @@ select * from perf_test(
4645 _bool_param => true
4746)
4847*/
48+
49+ create or replace function perf_test_arrays (
50+ _records int ,
51+ _text_param text ,
52+ _int_param int ,
53+ _ts_param timestamp ,
54+ _bool_param bool
55+ )
56+ returns table(
57+ id1 int [],
58+ foo1 text [],
59+ bar1 text [],
60+ datetime1 timestamp [],
61+ id2 int [],
62+ foo2 text [],
63+ bar2 text [],
64+ datetime2 timestamp [],
65+ long_foo_bar text [],
66+ is_foobar bool[]
67+ )
68+ language sql
69+ as
70+ $$
71+ select
72+ array[i + _int_param, i + _int_param + 1 , i + _int_param + 2 ] as id1,
73+ array[' foo' || ' _' || _text_param || ' _' || i::text , ' foo2' , ' foo3' ] as foo1,
74+ array[' bar' || i::text , ' bar2' , ' bar3' ] as bar1,
75+ array[(_ts_param::date ) + (i::text || ' days' )::interval, _ts_param::date + ' 1 days' ::interval, _ts_param::date + ' 2 days' ::interval] as datetime1,
76+ array[i+ 1 + _int_param, i+ 2 + _int_param, i+ 3 + _int_param] as id2,
77+ array[' foo' || ' _' || _text_param || ' _' || (i+ 1 )::text , ' foo' || ' _' || _text_param || ' _' || (i+ 2 )::text , ' foo' || ' _' || _text_param || ' _' || (i+ 3 )::text ] as foo2,
78+ array[' bar' || ' _' || _text_param || ' _' || (i+ 1 )::text , ' bar' || ' _' || _text_param || ' _' || (i+ 2 )::text , ' bar' || ' _' || _text_param || ' _' || (i+ 3 )::text ] as bar2,
79+ array[(_ts_param::date ) + ((i+ 1 )::text || ' days' )::interval, _ts_param::date + ' 1 days' ::interval, _ts_param::date + ' 2 days' ::interval] as datetime2,
80+ array[' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 2 )::text , ' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 3 )::text , ' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 4 )::text ] as long_foo_bar,
81+ array[(i % 2 )::boolean and _bool_param, ((i+ 1 ) % 2 )::boolean and _bool_param, ((i+ 2 ) % 2 )::boolean and _bool_param] as is_foobar
82+ from
83+ generate_series(1 , _records) as i
84+ $$;
85+ /*
86+ select * from perf_test_arrays(
87+ _records => 10,
88+ _text_param => 'abcxyz',
89+ _int_param => 999,
90+ _ts_param => '2024-01-01',
91+ _bool_param => true
92+ )
93+ */
94+
95+ create or replace function perf_test_record (
96+ _records int ,
97+ _text_param text ,
98+ _int_param int ,
99+ _ts_param timestamp ,
100+ _bool_param bool
101+ )
102+ returns setof record
103+ language sql
104+ as
105+ $$
106+ select
107+ i + _int_param as id1,
108+ ' foo' || ' _' || _text_param || ' _' || i::text as foo1,
109+ ' bar' || i::text as bar1,
110+ (_ts_param::date ) + (i::text || ' days' )::interval as datetime1,
111+ i+ 1 + _int_param as id2,
112+ ' foo' || ' _' || _text_param || ' _' || (i+ 1 )::text as foo2,
113+ ' bar' || ' _' || _text_param || ' _' || (i+ 1 )::text as bar2,
114+ (_ts_param::date ) + ((i+ 1 )::text || ' days' )::interval as datetime2,
115+ ' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 2 )::text as long_foo_bar,
116+ (i % 2 )::boolean and _bool_param as is_foobar
117+ from
118+ generate_series(1 , _records) as i
119+ $$;
120+ /*
121+ select perf_test_record(
122+ _records => 10,
123+ _text_param => 'abcxyz',
124+ _int_param => 999,
125+ _ts_param => '2024-01-01',
126+ _bool_param => true
127+ )
128+ */
129+
130+ create or replace function perf_test_record_arrays (
131+ _records int ,
132+ _text_param text ,
133+ _int_param int ,
134+ _ts_param timestamp ,
135+ _bool_param bool
136+ )
137+ returns setof record
138+ language sql
139+ as
140+ $$
141+ select
142+ array[i + _int_param, i + _int_param + 1 , i + _int_param + 2 ] as id1,
143+ array[' foo' || ' _' || _text_param || ' _' || i::text , ' foo2' , ' foo3' ] as foo1,
144+ array[' bar' || i::text , ' bar2' , ' bar3' ] as bar1,
145+ array[(_ts_param::date ) + (i::text || ' days' )::interval, _ts_param::date + ' 1 days' ::interval, _ts_param::date + ' 2 days' ::interval] as datetime1,
146+ array[i+ 1 + _int_param, i+ 2 + _int_param, i+ 3 + _int_param] as id2,
147+ array[' foo' || ' _' || _text_param || ' _' || (i+ 1 )::text , ' foo' || ' _' || _text_param || ' _' || (i+ 2 )::text , ' foo' || ' _' || _text_param || ' _' || (i+ 3 )::text ] as foo2,
148+ array[' bar' || ' _' || _text_param || ' _' || (i+ 1 )::text , ' bar' || ' _' || _text_param || ' _' || (i+ 2 )::text , ' bar' || ' _' || _text_param || ' _' || (i+ 3 )::text ] as bar2,
149+ array[(_ts_param::date ) + ((i+ 1 )::text || ' days' )::interval, _ts_param::date + ' 1 days' ::interval, _ts_param::date + ' 2 days' ::interval] as datetime2,
150+ array[' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 2 )::text , ' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 3 )::text , ' long_foo_bar_' || ' _' || _text_param || ' _' || (i+ 4 )::text ] as long_foo_bar,
151+ array[(i % 2 )::boolean and _bool_param, ((i+ 1 ) % 2 )::boolean and _bool_param, ((i+ 2 ) % 2 )::boolean and _bool_param] as is_foobar
152+ from
153+ generate_series(1 , _records) as i
154+ $$;
155+ /*
156+ select perf_test_record_arrays(
157+ _records => 10,
158+ _text_param => 'abcxyz',
159+ _int_param => 999,
160+ _ts_param => '2024-01-01',
161+ _bool_param => true
162+ )
163+ */
0 commit comments