cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Thoughts on how to improve string search queries

Bhanu1
New Contributor III

Please see sample code I am running below. What options can I explore to improve speed of query execution in such a scenario? Current full code takes about 4 hrs to run on 1.5 billion rows. Thanks!

SELECT
 fullVisitorId
 ,VisitId
 ,EventDate
 ,PagePath
 ,deviceCategory 
FROM ga360.ga_sessions a
WHERE
(
contains(lower(PagePath) , 'step-one')
OR contains(lower(PagePath) , 'step-two')
OR contains(lower(PagePath) , 'step-three')
)
AND not contains(utm_source,'ads')
AND hitstype = 'PAGE'
and a.EventDateKey >= 20200101

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @Bhanu1, When dealing with large datasets and slow query execution, there are several strategies you can explore to improve performance. Let’s dive into some options:

Indexing:

  • Indexing is a critical technique for enhancing SQL query performance on large tables. Ensure that you have appropriate indexes on the columns frequently queried. Since you mentioned that adding indexes is not an option, consider reevaluating the existing indexes. Sometimes, removing or modifying existing indexes can lead to better performance.
  • If possible, create a single-column index on each column used in your query. This provides SQL Server with something to work with for most queries.
  • Additionally, create specific indexes for the most common queries to optimize them further.

Partitioning:

Limit Returned Data:

Parallel Execution:

Remember that query optimization is often a combination of these techniques. Analyze your specific use case, monitor query execution plans, and test different approaches to find the best solution for your scenario. 🚀

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!