|
| 1 | +BEGIN; |
| 2 | + |
| 3 | +-- Match the normalized-handle predicates used by the admin social landing |
| 4 | +-- progress rollup so Postgres can narrow each platform table before aggregate |
| 5 | +-- work begins. |
| 6 | +CREATE INDEX IF NOT EXISTS idx_social_instagram_posts_landing_account_norm |
| 7 | + ON social.instagram_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 8 | + |
| 9 | +CREATE INDEX IF NOT EXISTS idx_social_tiktok_posts_landing_account_norm |
| 10 | + ON social.tiktok_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 11 | + |
| 12 | +CREATE INDEX IF NOT EXISTS idx_social_twitter_tweets_landing_account_norm |
| 13 | + ON social.twitter_tweets ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 14 | + |
| 15 | +CREATE INDEX IF NOT EXISTS idx_social_youtube_videos_landing_account_norm |
| 16 | + ON social.youtube_videos ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 17 | + |
| 18 | +CREATE INDEX IF NOT EXISTS idx_social_facebook_posts_landing_account_norm |
| 19 | + ON social.facebook_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 20 | + |
| 21 | +CREATE INDEX IF NOT EXISTS idx_social_threads_posts_landing_account_norm |
| 22 | + ON social.meta_threads_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 23 | + |
| 24 | +CREATE INDEX IF NOT EXISTS idx_social_ig_catalog_posts_landing_account_norm |
| 25 | + ON social.instagram_account_catalog_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 26 | + |
| 27 | +CREATE INDEX IF NOT EXISTS idx_social_tiktok_catalog_posts_landing_account_norm |
| 28 | + ON social.tiktok_account_catalog_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 29 | + |
| 30 | +CREATE INDEX IF NOT EXISTS idx_social_twitter_catalog_posts_landing_account_norm |
| 31 | + ON social.twitter_account_catalog_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 32 | + |
| 33 | +CREATE INDEX IF NOT EXISTS idx_social_youtube_catalog_posts_landing_account_norm |
| 34 | + ON social.youtube_account_catalog_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 35 | + |
| 36 | +CREATE INDEX IF NOT EXISTS idx_social_facebook_catalog_posts_landing_account_norm |
| 37 | + ON social.facebook_account_catalog_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 38 | + |
| 39 | +CREATE INDEX IF NOT EXISTS idx_social_threads_catalog_posts_landing_account_norm |
| 40 | + ON social.threads_account_catalog_posts ((ltrim(lower(coalesce(source_account, '')), '@'))); |
| 41 | + |
| 42 | +CREATE INDEX IF NOT EXISTS idx_social_instagram_profiles_landing_account_norm |
| 43 | + ON social.instagram_profiles ( |
| 44 | + (ltrim(lower(coalesce(normalized_username, username, source_account, '')), '@')), |
| 45 | + last_scraped_at DESC NULLS LAST, |
| 46 | + updated_at DESC NULLS LAST, |
| 47 | + id |
| 48 | + ); |
| 49 | + |
| 50 | +CREATE INDEX IF NOT EXISTS idx_pipeline_socialblade_landing_platform_handle_norm |
| 51 | + ON pipeline.socialblade_growth_data ( |
| 52 | + (lower(coalesce(nullif(platform, ''), 'instagram'))), |
| 53 | + (ltrim(lower(coalesce(nullif(account_handle, ''), instagram_handle, '')), '@')) |
| 54 | + ); |
| 55 | + |
| 56 | +COMMIT; |
0 commit comments