Search code examples
rdbimonetdbdbplyr

Why is my DBI connector doing a dummy query with predicate "where 0 = 1"?


I have some R test code that I use to connect to a MonetDB instance.

I notice that for each connection that I create through tbl(conn, "some_table") I somehow always end up with a 'primer' query of the form

SELECT *
FROM "some_table" AS "zzz1"
WHERE (0 = 1)

So if I run the code

conn <- dbConnect(MonetDB.R(), host="localhost", dbname="testdb", user="monetdb", password="monetdb")
foo <- tbl(conn, "foo")
foo %>% filter(bar %like%  '%baz%') %>% collect()

I end up with two queries in the output

QQ: 'SELECT *
FROM "foo" AS "zzz1"
WHERE (0 = 1)'
QQ: Query result for query 0 with 0 rows and 34 cols, 0 rows.
QQ: 'SELECT *
FROM "foo")
WHERE ("bar" LIKE '%baz%')'
QQ: Query result for query 1 with 20 rows and 2 cols, 20 rows.

I do not understand where this additional query comes from. As far as I know DBI should not perform any dummy query by default.


Solution

  • dplyr auto-generates and runs this query to get the columns for the table. This is needed to figure out whether bar in filter exists in the table for example.