Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
Very slow query against view in postgres - possible to enhance?

I have a postgres DB with some million entries (and growing fast). I've created a view of that DB where some of the columns of each row is concatenated and aggreagated (in this format):

concat         | count
david55single    5

What I'm doing is getting a string in this format, and I check the view if that exact string is in the view, and what the count is. This is my query:

SELECT count from concatview WHERE concat = '<somestring>'; 

This query takes a really long time, which is bad since we do this query on each request from a user. Is there any way to enhance the time of the query? From what I've understood from the documentation it's only possible to index materialized view? Do I need to create a materialized view instead and refresh the view quite often, or is there any other ways to enhance the regular view?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

 create index on mytab(col1||col2||col3)

being certain to use the same exact syntax on the index as you do in the view. If you're using the concat() function to do your concatenation, you'll need to create an IMMUTABLE version of concat() (immutable means that given the same input, it always returns the same output, and the standard concat is not marked immutable, but in many use cases it can safely be wrapped in an immutable function). This will allow queries against the view to utilize the index.

Note: the || concatenation operator won't play well if ANY of the columns are nullable.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!