If we pass a string literal as a second argument (select select_test('1','')) then everything works as expected: query does index scan over 'tbl', using the index on 'id':
# select select_test('1','');
NOTICE: 00000: Bitmap Heap Scan on tbl (cost=1.28..5.48 rows=4 width=64)
NOTICE: 00000: Recheck Cond: (id = '1'::text)
NOTICE: 00000: -> Bitmap Index Scan on tbl_id_idx (cost=0.00..1.28 rows=4 width=0)
NOTICE: 00000: Index Cond: (id = '1'::text)
However, if we pass current_user as a second argument (which is completely unused in the body of the function), the plan suddenly changes:
# select select_test('1',current_user);
NOTICE: 00000: Seq Scan on tbl (cost=0.00..21.00 rows=4 width=64)
NOTICE: 00000: Filter: (id = '1'::text COLLATE "C")
Note that '1' had suddenly become ('1'::text COLLATE "C"), and this prevents the use of the index (which has collation 'en_US.UTF8').
The same behavior could be observed by using current_user as a first argument, or as a part of an expression for any of the arguments, such as:
select select_test('1',''||current_user);
select select_test(current_user,'');
select select_test('1',current_user::text);
Same thing happens with session_user, current_schema and current_database()
The only variant that works (that I was able to find) is:
select select_test('1','current_user'::text);
I am observing this on 13.6, 15.6.
Best regards, Dmytro