Skip to content

[#385] Implementation of asterisk in select column list

Ganesh Mahesh requested to merge zylog1O1/YDBOcto:ydbocto385 into master

Parser communicates the presence of asterisk to query_specification.c by creating an empty ColumnListAlias node in the position of select column list where asterisk occurs.

query_specification.c determines the presence of asterisk by checking ColumnListAlias nodes sent from parser. Specifically column_list value is compared with NULL which when true indicates an empty node or an asterisk.

query_specification.c is modified to handle multiple asterisk usages in select column list. This is done by traversing the selection column list and when asterisk is found, ColumnListAlias nodes for asterisk are formed and appended to the select column list based on its position in the query. Note: here the original place holder is replaced with the asterisk list.

Column list alias for asterisk is only formed once. All other occurrences of asterisk use the result of the first call. Copy of the result is appended to the list whenever an asterisk is seen after the first call.

Usecases handled:

-- Single asterisk at the beginning of select column list
select * from names;
select *,n1.id from names n1;
select *,n1.id,n2.id from names n1, names n2;
-- Single asterisk at different positions in select column list
select n1.id,*,n2.id from names n1, names n2;
select n1.id,n2.id,* from names n1, names n2;
-- Multiple asterisk usage
select n1.id,*,n2.id,*,n1.id from names n1, names n2;

The empty ColumnListAlias node used by parser to communicate asterisk presence is de-allocated at the end of run_query along with other memory chunks.

QueryGenerator.m is modified to add -- sort-needed-check when select list has asterisk along with an ORDER BY for outermost query. Also selectList routine is modified to enable asterisk usage with other columns in select column list. Multiple occurrence of asterisk is avoided in the presence of DISTINCT and when join count >1 as it generates Maximum number of subscripts exceeded error.

Before this change processing of below type of queries where both parent and sub query has asterisk in select column list along with a natural join in subquery failed.

select * from (select * from names n1 natural join names n2) n3;

This is because duplicate_of_column field of cla was not cleared after processing asterisk in the subquery select column list. As a result when parent query was processed, code responsible for processing natural join was being executed. This lead to failure of the following assert assert(NATURAL_JOIN == cur_join->type); in process_asterisk for the parent query. After this change, the duplicate column field is cleared once asterisk processing is complete. This is possible because, at the time of common column processing, the value of duplicate column field is table number which is only required till asterisk processing is complete. So the field is set to NULL. This prevents execution of natural join block when parent query is executed thus avoiding the failure.

Misc change:

  • Adding query file exists check to run multiple query interface in test_helpers
Edited by Ganesh Mahesh

Merge request reports