File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
xyz-psql-connector/src/main/resources Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -1494,6 +1494,7 @@ CREATE OR REPLACE FUNCTION xyz_config.naksha_fetch_newer_transactions( in_hst_sc
14941494AS
14951495$BODY$
14961496DECLARE
1497+ table_name TEXT ;
14971498 txn_stmt TEXT ;
14981499 txn_record RECORD;
14991500 crt_txn_rec_id int8;
@@ -1502,12 +1503,17 @@ DECLARE
15021503 fetched_count int ;
15031504BEGIN
15041505 -- Statement to fetch newer transaction Id(s) from Transactions table for a given space
1506+ -- We use "schema" and "table" based query (instead of space) to hit the right index
1507+ -- txn_stmt:= format('SELECT t.id, t.txn FROM xyz_config.transactions t '
1508+ -- ||'WHERE t.space = $1 AND t.id >= $2 ORDER BY t.id ASC LIMIT %s', in_limit_rows+1);
15051509 txn_stmt:= format(' SELECT t.id, t.txn FROM xyz_config.transactions t '
1506- || ' WHERE t.space = $1 AND t.id >= $2 ORDER BY t.id ASC LIMIT %s' , in_limit_rows+ 1 );
1510+ || ' WHERE t."schema" = $1 AND t."table" = $2 AND t. id >= $3 ORDER BY t.id ASC LIMIT %s' , in_limit_rows+ 1 );
15071511
1512+ table_name := replace(in_hst_table, ' _hst' , ' ' );
15081513 fetched_count := 0 ;
15091514 -- Fetch transaction Id(s)
1510- FOR txn_record IN EXECUTE txn_stmt USING in_space, in_last_txn_id LOOP
1515+ -- FOR txn_record IN EXECUTE txn_stmt USING in_space, in_last_txn_id LOOP
1516+ FOR txn_record IN EXECUTE txn_stmt USING in_hst_schema, table_name, in_last_txn_id LOOP
15111517 EXIT WHEN fetched_count >= in_limit_rows;
15121518 -- RAISE NOTICE 'Transaction fetched is %', txn_record;
15131519
You can’t perform that action at this time.
0 commit comments