This message was deleted.
# troubleshooting
s
This message was deleted.
s
The SQL query is basically like this:
Copy code
SELECT COUNT(*) as total,
  SUM(impressions) AS impressions
FROM (
    SELECT dim1,
      dim2 SUM(impressions) AS impressions (
        (SUM(some_metric) * 1.0) / SUM(impressions)
      ) AS takeRate ---notice the alias here 
    FROM druid_datasource
    WHERE date BETWEEN '20230203' AND '20230203'
      AND country_desc IN ('Algeria')
    GROUP BY 1,
      2
    HAVING takeRate BETWEEN 0 AND 1 ---notice the usage of alias in having clause
  )
WHERE impressions BETWEEN 1000 AND 2000
When druid console's smart query limit toggle is on, the having clause is present in the sub query.
Copy code
"postAggregations": [],
	"having": {
		"type": "filter",
		"filter": {
			"type": "and",
			"fields": [{
				"type": "expression",
				"expression": "(((\"a1\" * 1.0) / \"a0\") >= 0)"
			}, {
				"type": "expression",
				"expression": "(((\"a1\" * 1.0) / \"a0\") <= 1)"
			}]
		},
		"finalize": true
	},
	"limitSpec": {
		"type": "NoopLimitSpec"
	},
When the console's smart query limit toggle is off, the having clause isn't present in the sub-query anymore.
Copy code
"postAggregations": [],
	"having": null,
	"limitSpec": {
		"type": "NoopLimitSpec"
	}
Instead, what I noticed was that the having clause was re-written to a where clause in the outer query.
Copy code
"filter": {
		"type": "and",
		"fields": [{
			"type": "bound",
			"dimension": "impressions",
			"lower": "1000",
			"upper": "2000",
			"lowerStrict": false,
			"upperStrict": false,
			"extractionFn": null,
			"ordering": {
				"type": "numeric"
			}
		}, {
			"type": "bound",
			"dimension": "v0",
			"lower": "0",
			"upper": "1",
			"lowerStrict": false,
			"upperStrict": false,
			"extractionFn": null,
			"ordering": {
				"type": "numeric"
			}
		}]
	}
In our case, when the query has smart query limit toggle on, it returns some results. When the toggle is off, it doesn't return any results.
v
that is strange, why would rewriting a HAVING on the inner query to a WHERE on the outer query change anything? It seems like a chill thing to do...
The fact that you are calling it
smart query limit toggle
tells me that you are on an older version of Druid. In today's Druid it was renamed to "Limit inline results" and it is a checkbox now
Do you see the same behavior in Druid 25? Do you have a way of checking?
I have Druid 25 in front of me, I am trying my best to reproduce this but can not
s
You are right, I am using Druid 0.20.0.
What does the explain plan look like with and without the limit enabled?
v
the only diff is the limit spec (as you would expect) and the UUID
Are you able to upgrade your Druid to a later version?