Simplify columnar perf example (#6526)

Rewrite the plpython function to generate random words in SQL to
simplify the usage and run the example.
pull/6533/head
Fabrízio de Royes Mello 2022-12-01 16:05:40 -03:00 committed by GitHub
parent 29f0196fdf
commit 37f3dff1ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 10 deletions

View File

@ -234,16 +234,14 @@ CREATE TABLE perf_columnar(LIKE perf_row) USING COLUMNAR;
## Data ## Data
```sql ```sql
CREATE OR REPLACE FUNCTION random_words(n INT4) RETURNS TEXT LANGUAGE plpython2u AS $$ CREATE OR REPLACE FUNCTION random_words(n INT4) RETURNS TEXT LANGUAGE sql AS $$
import random WITH words(w) AS (
t = '' SELECT ARRAY['zero','one','two','three','four','five','six','seven','eight','nine','ten']
words = ['zero','one','two','three','four','five','six','seven','eight','nine','ten'] ),
for i in xrange(0,n): random (word) AS (
if (i != 0): SELECT w[(random()*array_length(w, 1))::int] FROM generate_series(1, $1) AS i, words
t += ' ' )
r = random.randint(0,len(words)-1) SELECT string_agg(word, ' ') FROM random;
t += words[r]
return t
$$; $$;
``` ```