Rails Postgres Partial Indexing

Postgres has a nice feature where you can index only the values you want to query on. Today I learned that Rails has a nice shortcut for taking advantage of said feature.While working on a new Box Out feature, I needed to query for graphics that have been shared on social media.I had a graphics table with a tweet_id column. I wanted to query for graphics that have been shared on twitter (aka tweet_id IS NOT NULL). The table is in the hundreds of thousands of rows, so I wanted to index tweet_id to help the query along. I was going to a plain old add_index. But then I remembered that you can do partial indexes.
Rails Postgres Partial Indexing #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/rails-postgres-partial-indexing

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles