https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
h

helpful-alligator-75316

03/19/2024, 7:33 PM
Also, is there any way that I can add the experiment filters to metric queries? Every time Growthbook runs it blows up the database because many of the queries run w/ no filters and query the entire table. e.g. this metric:
Copy code
select
  min(timestamp) timestamp,
  session_id,
  anonymous_id,
  host,
  countIf(event = 'page_viewed') page_views
from events
group by session_id, anonymous_id, host
having page_views < 2
Turns into this query which has no timestamp or experiment_id filter:
Copy code
__metric as (-- Metric (Bounce Rate)
  SELECT
    session_id as session_id,
    1 as value,
    m.timestamp as timestamp
	  FROM
	    ( -- This subquery is scanning the entire database (would be nice to limit by experiment_id or timestamp somehow
		select
		  min(timestamp) timestamp,
		  session_id,
		  anonymous_id,
		  host,
		  countIf(event = 'page_viewed') page_views
		from events
		group by session_id, anonymous_id, host
		having page_views < 2
	) m  
    WHERE m.timestamp >= toDateTime('2024-03-01 16:15:00', 'UTC') AND m.timestamp <= toDateTime('2024-03-19 19:20:50', 'UTC')
)
a

agreeable-elephant-38605

03/19/2024, 9:21 PM
you can use sql templates in your metric definition to filter based on experiment duration https://docs.growthbook.io/app/metrics#sql-templates, for example:
Copy code
select
  min(timestamp) timestamp,
  session_id,
  anonymous_id,
  host,
  countIf(event = 'page_viewed') page_views
from events
where timestamp >= '{{ startDate }}'
  AND timestamp < '{{ endDate }}'
group by session_id, anonymous_id, host
having page_views < 2
h

helpful-alligator-75316

03/19/2024, 9:22 PM
ah thats excellent! I'll add those in. Thank you
5 Views