Skip to content

Extra arguments in explain() do not reach backend specific sql_query_explain -method #783

@rsund

Description

@rsund

Postgres-backend includes a format argument to the sql_query_explain -method. However, that argument never survives to the function, and default value is always used. This is very restrictive for the backends that would benefit for passing arguments to the method.

To demonstrate the issue, the following reprex changes the sql_query_explain -method of SQLiteConnection so that the value of the argument becomes visible.

library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)

# Adding format argument (from Postgres explain) to SQLite explain
sql_query_explain.SQLiteConnection <- function(con, sql, format = "text", ...) {
  dbplyr:::cat_line("Parameter 'format' with value: ", format)
  build_sql("EXPLAIN QUERY PLAN ", sql, con = con)
}
assignInNamespace("sql_query_explain.SQLiteConnection", sql_query_explain.SQLiteConnection, ns = "dbplyr")

con = DBI::dbConnect(RSQLite::SQLite(), ":memory:")
df <- copy_to(con, tibble(x=1))
df %>% explain(format="json") # Value below should be: json
#> <SQL>
#> SELECT *
#> FROM `tibble(x = 1)`
#> 
#> <PLAN>
#> Parameter 'format' with value: text
#>   id parent notused             detail
#> 1  2      0       0 SCAN tibble(x = 1)
DBI::dbDisconnect(con)

Created on 2022-02-18 by the reprex package (v2.0.1.9000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions