Skip to content
Radim Bača edited this page Mar 12, 2019 · 3 revisions

Tags in rewriting_2019.xml

Tags are used to label variants with specific features. In some cases, we use tags to label a pair of variants where some straightforward rewriting is applied. Let us call such tags as a rewriting tags.

Now, let us describe the important tags in a detail

  • T3A, T3B - Rewriting tags. Rewriting rule removes some attributes behind the GROUP BY and use max aggregation function to keep them in the SELECT list. This rewriting is possible only when the removed attributes are functionally dependent on an attribute that is preserved in the GROUP BY list.

    select id, name from student group id, name`
    select id, max(name) from student group by id
  • T4A, T4B - Rewriting tags. Rewriting transform a query using a dependent subquery into a query with CROSS APPLY.

     select st.name, st.login from Student st
     where
     (
       select count(*) from Study sy where sy.login = st.login and sy.course_id = 10
     ) != 0
     select st.name, st.login from Student st
     cross apply
     (
       select count(*) c from Study sy where sy.login = st.login and sy.course_id = 10
     ) t
     where t.c != 0
  • T5A (No Pk) - This tag label a variant that does not require a primary key on the id attribute to be defined in order to be equivalent to the [a] variant in the test.

  • T5B (Pk) - This tag label a variant that requires a primary key on the id attribute to be defined in order to be equivalent to the [a] variant in the test.

  • T6A, T6B - Rewriting tags. Rewriting rule replace the DISTINCT construct using the GROUP BY and the other way around.

     select distinct st.year
     from Student st
     select st.year
     from Student st
     group by st.year
  • T7A, T7B - Rewriting tags. Rewriting rule pushes the DISTINCT into a subquery.

     select distinct s1.login
     from Study s1
     where s1.login in (select s2.login from Study s2 where s2.course_id = 1) and
           s1.login in (select s2.login from Study s2 where s2.course_id = 2)
     select s1.login
     from (select distinct login from Study) s1
     where s1.login in (select s2.login from Study s2 where s2.course_id = 1) and
           s1.login in (select s2.login from Study s2 where s2.course_id = 2)
Clone this wiki locally