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

default to using inline sql views for reports #18822

Merged
merged 2 commits into from
Jun 18, 2019

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented May 29, 2019

Depends upon:

Overview

When we include virtual attributes in a query, it runs the query for every row in the result set.
For pages like the services explorer, this is very slow.

We solved this issue by introducing inline views and only running the virtual attribute for the rows in the result set. #18543 introduced it as an opt-in feature.

This has affectionately been called the "Turbo Button".

Before

Only use the improved performance in certain screens since there is a concern this may break screens. Only the Services screen has opted-in for improved performance (on hammer and master/ivanchuk)

After

Change the turbo button from op-in to an op-out. So all screens will have it.

This PR did require a change to virtual attributes and custom attribute: Fixed a bug in Virtual Attributes to properly escape sql aliases. Removed work around for said bug in Custom Attributes.

Numbers

For one example, see #18543
This will have impact on any screen that displays counts. e.g.: explorers for ems, host, and vms.

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one comment is the only thing I have to add for this. I think it is fine that are enabling this across the board and having it go through it through the QE test cycle, but I might be biased and missing something.

@@ -319,7 +319,7 @@ def generate_basic_results(options = {})

## add in virtual attributes that can be calculated from sql
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank?
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view]
rbac_opts[:use_sql_view] = true unless db_options && db_options[:use_sql_view] == false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two alternative ideas on how to handle this:

Option 1

Maybe make this "falsey", where we still do an "existence" check, but then simply check that the value is falsey:

rbac_opts[:use_sql_view] = true unless db_options.has_key?(:use_sql_view) && !db_options[:use_sql_view]

Option 2

Alternatively, we can change this in Rbac so that this code here only sets it if it exists:

rbac_opts[:use_sql_view] = db_options[:use_sql_view] if db_options.has_key?(:use_sql_view)

And then in Rbac.search, we do a:

def search(options={})
  # ...
  options[:use_sql_view] ||= true

  # ...
end

Or do you think that is too heavy handed?

Copy link
Member

@jrafanie jrafanie May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or something like this:

rbac_opts[:use_sql_view] = db_options[:use_sql_view] != false

I do think there is some merit to considering option 2 though.

You can't memoize with a false value though, so perhaps something like:

def search(options={})
  # ...
  options[:use_sql_view] = true unless options[:use_sql_view] == false

  # ...
end

EDIT: Haha, I typod... had = false instead of == false

@NickLaMuro
Copy link
Member

@kbrock You might want to look into the tests failures on this one, as they seem to be related to this change.

We might possibly want to run the test suite of the API and UI with this change in place prior to merging.

@Fryguy
Copy link
Member

Fryguy commented May 31, 2019

I also suggest running the manageiq-ui-classic specs as the UI is heavily dependent on reports

@kbrock kbrock force-pushed the turbo_for_all branch 2 times, most recently from 6a8edc8 to 0e5652b Compare June 3, 2019 13:06
@kbrock
Copy link
Member Author

kbrock commented Jun 3, 2019

@kbrock You might want to look into the tests failures on this one, as they seem to be related to this change.

We might possibly want to run the test suite of the API and UI with this change in place prior to merging.

Thnx
it a hidden issue with virtual attributes for a while. I put in a PR over there for it

I've run this through all the views (which should be the only real issue) but running a full test suite is a good idea. will do today

@kbrock
Copy link
Member Author

kbrock commented Jun 3, 2019

also, @NickLaMuro
Sorry about the &. gook, rubocop complained about the db_options && db_options.key?(:use_sql_view) -- and to be honest, this is the primary use case of that method (since && . => &.)

@kbrock kbrock changed the title default to using inline sql views for reports [WIP]default to using inline sql views for reports Jun 5, 2019
@kbrock
Copy link
Member Author

kbrock commented Jun 5, 2019

WIP: waiting for new release of virtual attributes

@miq-bot miq-bot added the wip label Jun 5, 2019
@kbrock kbrock changed the title [WIP]default to using inline sql views for reports default to using inline sql views for reports Jun 6, 2019
@miq-bot miq-bot removed the wip label Jun 6, 2019
@kbrock
Copy link
Member Author

kbrock commented Jun 10, 2019

I also suggest running the manageiq-ui-classic specs as the UI is heavily dependent on reports

all passed.

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't have the capacity to put up any real stink about this PR.

I am still unsure why this is in existence to begin with, since it doesn't seem to be helping fix anything in particular for the Rails upgrade effort and there is no BZ associated, so I only can assume this is one of "Keenan's random musings" I am all to familiar with. Also, the example of "one case where this makes things better" seems very pseudo science-y and far from definitive evidence this will make the world a better place.

But I also just had something merged that broke in ten different ways and I probably am being a hypocrite, so maybe just do what you want, man. The Dude abides.

@@ -319,7 +319,7 @@ def generate_basic_results(options = {})

## add in virtual attributes that can be calculated from sql
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank?
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view]
rbac_opts[:use_sql_view] = db_options&.key?(:use_sql_view) ? db_options[:use_sql_view] : true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I am out... review this yourself since you used the & operator...

Copy link
Member

@NickLaMuro NickLaMuro Jun 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also why I hate this operator since it just adds cognitive load as a result of saving key strokes...

But anyway, is this now defaulting to true, and favoring the option value when it is present?

So the above change then translates to this:

- rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view]
+ rbac_opts[:use_sql_view] = true
+ rbac_opts[:use_sql_view] = db_options[:use_sql_view] if db_options && db_options.key?(:use_sql_view)

Correct?

Edit: I realized that I reviewed this PR weeks ago, and commented on this specific line, so this most likely was a "yes" to answering the last question.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But anyway, is this now defaulting to true, and favoring the option value when it is present?

Change the turbo button from op-in to an op-out. So all screens will have it.
-- the after section of the description

Yes, sorry that rubocop wanted me to change it:

- rbac_opts[:use_sql_view] = db_options && db_options.key?(:use_sql_view) ? db_options[:use_sql_view] : true
+ rbac_opts[:use_sql_view] = db_options&.db_options.key?(:use_sql_view) ? db_options[:use_sql_view] : true

I will change to:

- rbac_opts[:use_sql_view] = db_options && db_options.key?(:use_sql_view) ? db_options[:use_sql_view] : true
+ rbac_opts[:use_sql_view] = db_options == nil || db_options.fetch(:use_sql_view) { true }

@@ -97,7 +97,7 @@ def paged_view_search(options = {})
)
search_options.merge!(:limit => limit, :offset => offset, :order => order) if order
search_options[:extra_cols] = va_sql_cols if va_sql_cols.present?
search_options[:use_sql_view] = true if db_options && db_options[:use_sql_view]
search_options[:use_sql_view] = db_options&.key?(:use_sql_view) ? db_options[:use_sql_view] : true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh... again!!

... and to be honest, this is the primary use case of that method (since && . => &.)

@kbrock [ref]

Nope, doesn't make it better, and still looks like and overloaded version of the bitwise AND operator in my eyes.

@kbrock kbrock force-pushed the turbo_for_all branch 2 times, most recently from e7d6267 to b3babcd Compare June 18, 2019 18:32
for reports and the report data (right hand of screen)
allow the use of inline sql views (aka the "turbo button")

when there are virtual attributes in the primary query, they get run
for every row (even those not brought back)

this option allows rbac to optimize the query in these cases to
run the virtual attributes in an outer query, so they only get run for
the few rows brought back
virtual attributes should no contain aliases
It should contain a grouping (parens on the outside)

This alias was added due to a bug in virtual attributes that did not
properly quote alias values. Now that that has been fixed, the alias
can be removed.
@miq-bot
Copy link
Member

miq-bot commented Jun 18, 2019

Checked commits kbrock/manageiq@eb53085~...9dc5b0c with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
4 files checked, 0 offenses detected
Everything looks fine. 🍪

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me. Been provided some context out of band, so I am more comfortable approving this PR now. 🐑 🇮🇹

@@ -318,7 +318,7 @@ def generate_basic_results(options = {})

## add in virtual attributes that can be calculated from sql
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank?
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view]
rbac_opts[:use_sql_view] = db_options.nil? || db_options.fetch(:use_sql_view) { true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this out of band, but this could technically be:

rbac_opts[:use_sql_view] = db_options.nil? || db_options.fetch(:use_sql_view, true)

But I don't think it is worth another rebase and CI run, and rubocop doesn't seem to care. Just an FYI.

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jrafanie jrafanie self-assigned this Jun 18, 2019
@jrafanie jrafanie merged commit 790ee9c into ManageIQ:master Jun 18, 2019
@jrafanie
Copy link
Member

💣 🔥 🚒

@NickLaMuro
Copy link
Member

NickLaMuro commented Jun 18, 2019

Note: We have our first victim after merging this:

https://travis-ci.org/ManageIQ/manageiq-ui-classic/jobs/547432152

Quick fix done in #18892

@mfeifer mfeifer added this to the Sprint 114 Ending Jun 24, 2019 milestone Jan 27, 2020
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.

6 participants