:PROPERTIES: :ID: 266d19c2-5ecd-48af-a9d4-4b0a7d3d5696 :END: #+title: 2022-03-29 * Get list of subscribers with non-normalized tags on active accounts :PROPERTIES: :header-args:sql: :engine postgresql :cmdline "-U postgres postgres" :dir /docker:postgres: :exports both :cache yes :END: Investigating the impact of the new [[id:d06d3ab4-c2d0-47c3-aae1-4395567fc3d2][Tag Normalization]] rules on existing subscribers on active accounts. ** Gathering data I imported a dump of the =subscriber_tags= table from [[id:dd113e53-6144-4cb2-a4aa-da3dc2e3e6ea][AppDB]] as well as the =list.subscribers= table data for all active accounts (~SELECT s.* FROM list.subscribers s JOIN accounts a ON (a.a_id = s.account_id) WHERE a.status_id < 7~) I then built a table of subscribers having tags that do not match our validation rules. #+begin_src sql :exports code :eval never CREATE TABLE invalid_tags AS SELECT s.list_id, s.account_id, t.subscriber_id, tag FROM subscribers s JOIN subscriber_tags as t ON (s.id = t.subscriber_id) , unnest(tags) tag WHERE tag != normalize_tag(tag) #+end_src ** Subscribers on active accounts #+begin_src sql SELECT COUNT(*) FROM subscribers #+end_src #+RESULTS[073c7d5b524a0577c83785ca6051ad010990c18a]: | count | |----------| | 16650026 | ** Subscribers with invalid tags #+begin_src sql SELECT COUNT(DISTINCT subscriber_id) FROM invalid_tags #+end_src #+RESULTS[6ff96db184978da7271a89499c58d40cff8daebf]: | count | |--------| | 239291 | ** Accounts with subscribers with invalid tags #+begin_src sql SELECT COUNT(DISTINCT account_id) FROM invalid_tags; #+end_src #+RESULTS[f45bb88f747f30295132bcd75861b98721cd5341]: | count | |-------| | 16 | #+begin_src sql SELECT DISTINCT account_id FROM invalid_tags #+end_src #+RESULTS[ff2ba7ea0c8dc285f2be2a20afb0d0c786f4dac1]: | account_id | |------------| | 1833 | | 211344 | | 13492 | | 212837 | | 216738 | | 213819 | | 16479 | | 215217 | | 104120 | | 215067 | | 213122 | | 14656 | | 111262 | | 214928 | | 44749 | | 91 |