-
- Downloads
Nested queries have limits which can defeat their purpose (#41051) (#41262)
* Nested queries have limits which can defeat their purpose
Consider a query
```sql
select count(*) from {{#199}}
```
This query should return the number of distinct rows in the query
defined by 199. But it's actually limited by the excel limit of
1048575. And that's because when the value of `{{#199}}` is expanded it
has that limit applied as normal.
```clojure
qp=> (let [card-id 199] ;; use a valid card id for you
(-> {:database 1,
:type :native,
:native {:query "select count(*) from {{ref}}"
:template-tags {:ref {:card-id card-id
:type :card
:name "ref"
:display-name "ref"}}}
:middleware {:disable-max-results? true}}
qp.compile/compile
:query
(metabase.db.query/format-sql )
println))
select
count(*)
from
(
SELECT
"PUBLIC"."ORDERS"."ID" AS "ID",
"PUBLIC"."ORDERS"."TOTAL" AS "TOTAL"
FROM
"PUBLIC"."ORDERS"
LIMIT
1048575
)
```
But we can suppress this limit when substituting a query inside yielding
```sql
select
count(*)
from
(
SELECT
"PUBLIC"."ORDERS"."ID" AS "ID",
"PUBLIC"."ORDERS"."TOTAL" AS "TOTAL"
FROM
"PUBLIC"."ORDERS"
)
```
And this is proper because we want to limit the _outer_ query, not
internal queries.
* Remove limit from test expectation
* stupid trailing space
* another subquery test
* Use helper function to disable limit middleware
Co-authored-by:
dan sutton <dan@dpsutton.com>
Showing
- src/metabase/driver/common/parameters/values.clj 2 additions, 1 deletionsrc/metabase/driver/common/parameters/values.clj
- test/metabase/driver/common/parameters/values_test.clj 1 addition, 2 deletionstest/metabase/driver/common/parameters/values_test.clj
- test/metabase/query_processor/middleware/parameters_test.clj 1 addition, 2 deletionstest/metabase/query_processor/middleware/parameters_test.clj
Loading
Please register or sign in to comment