add distinct in all patterns