Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concise logging format for the binds of casted values #41136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Jan 16, 2021

Related issue #41133.

In #39106, I've allowed binds of casted values as an alternative of the
legacy binds (an array of [column || nil, value]) to deprecate and
remove the legacy binds support in a future version of Rails.

At that time, I've respected the existing logging format for binds.

i.e.

# legacy binds
conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [[nil, 1], [nil, 2]])
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [[nil, 1], [nil, 2]]

# casted binds
conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [1, 2])
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [[nil, 1], [nil, 2]]

To improve the performance of generating IN clause, 72fd0ba avoids
build_bind_attribute for each values, so now binds has become casted
values.

conn.select_all(Event.where(id: [1, 2]))
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [[nil, 1], [nil, 2]]

Regardless of whether 72fd0ba avoids build_bind_attribute or not, the
logging format for the binds of casted values is odd (at least not
pretty to me).

I'd like to concise the logging format to just use casted values.

conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [1, 2])
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [1, 2]

conn.select_all(Event.where(id: [1, 2]))
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [1, 2]

Related issue rails#41133.

In rails#39106, I've allowed binds of casted values as an alternative of the
legacy binds (an array of `[column || nil, value]`) to deprecate and
remove the legacy binds support in a future version of Rails.

At that time, I've respected the existing logging format for binds.

i.e.

```ruby
# legacy binds
conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [[nil, 1], [nil, 2]])
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [[nil, 1], [nil, 2]]

# casted binds
conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [1, 2])
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [[nil, 1], [nil, 2]]
```

To improve the performance of generating IN clause, 72fd0ba avoids
`build_bind_attribute` for each values, so now binds has become casted
values.

```ruby
conn.select_all(Event.where(id: [1, 2]))
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [[nil, 1], [nil, 2]]
```

Regardless of whether 72fd0ba avoids `build_bind_attribute` or not, the
logging format for the binds of casted values is odd (at least not
pretty to me).

I'd like to concise the logging format to just use casted values.

```ruby
conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [1, 2])
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [1, 2]

conn.select_all(Event.where(id: [1, 2]))
# (0.1ms)  SELECT * FROM events WHERE id IN (?, ?)  [1, 2]
```
@kamipo kamipo force-pushed the concise_logging_format_for_casted_binds branch from 65352ba to dd2cb97 Compare January 16, 2021 02:01
@ricardotk002
Copy link
Contributor

@kamipo I opened a related PR a few days ago #41068 to try to keep the original format. Should we close it? Considering that the format seems to be entering deprecation.

@kamipo
Copy link
Member Author

kamipo commented Jan 20, 2021

I suspect that avoiding build_bind_attribute in 72fd0ba is intentional for the performance but changing logging format is accidental.

I've requested a review from the author to leave it up to decide which one to take.

@rails-bot
Copy link

rails-bot bot commented Apr 20, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Apr 20, 2021
@kamipo kamipo removed the stale label Apr 24, 2021
@rails-bot
Copy link

rails-bot bot commented Jul 23, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Jul 23, 2021
@kamipo kamipo removed the stale label Jul 28, 2021
@rails-bot
Copy link

rails-bot bot commented Oct 26, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Oct 26, 2021
@kamipo kamipo removed the stale label Oct 26, 2021
@rails-bot
Copy link

rails-bot bot commented Jan 24, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Jan 24, 2022
@rails-bot rails-bot bot closed this Jan 31, 2022
@kamipo kamipo reopened this Feb 26, 2022
@rails-bot rails-bot bot removed the stale label Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants