Skip to content

Instantly share code, notes, and snippets.

@onderkalaci
Last active August 23, 2016 14:41
Show Gist options
  • Save onderkalaci/f3426940a036531a6cef66427e02d720 to your computer and use it in GitHub Desktop.
Save onderkalaci/f3426940a036531a6cef66427e02d720 to your computer and use it in GitHub Desktop.
-- create and distribute table
CREATE TABLE main_table (user_id int, username text, timeout bigint, occuruence_time date);
SELECT master_create_distributed_table('main_table', 'user_id', 'hash');
SELECT master_create_worker_shards('main_table', 16, 2);
CREATE TABLE reference_table (user_id int, username text, timeout bigint, occuruence_time date);
SELECT master_create_distributed_table('reference_table', 'user_id', 'hash');
SELECT master_create_worker_shards('reference_table', 16, 2);
-- Create a function which gets a regclass paremeter
CREATE OR REPLACE FUNCTION simpleTestFunction(regclass)
RETURNS text AS
$$
DECLARE
strresult text;
BEGIN
RETURN md5($1::text);
END;
$$
LANGUAGE 'plpgsql' STABLE;
-- Run the query
-- Before the patch, we push down the regclass itself
SELECT * FROM main_table WHERE simpleTestFunction('main_table') = '%test%';
-- DETAIL: query string: "SELECT user_id, username, timeout, occuruence_time FROM main_table_102008 main_table WHERE (public.simpletestfunction('public.main_table'::regclass) = '%test%'::text)"
-- WARNING: relation "public.main_table" does not exist
-- CONTEXT: while executing command on localhost:9700
-- After the patch, we push down the regclass extended with shardId
SELECT * FROM main_table WHERE simpleTestFunction('main_table') = '%test%';
-- DETAIL: query string: "SELECT user_id, username, timeout, occuruence_time FROM main_table_102008 main_table WHERE (public.simpletestfunction(('main_table_102008'::text)::regclass) = '%test%'::text)"
SELECT * FROM main_table, reference_table WHERE simpleTestFunction('main_table') = '%test%';
DEBUG: StartTransactionCommand
DEBUG: StartTransaction
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment