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

[fix][server] Fix webapp crash when using component filter #3887

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

vodorok
Copy link
Contributor

@vodorok vodorok commented Apr 18, 2023

This is the query produced by the modified logic:

SELECT
	reports.id AS reports_id, 
	reports.file_id AS reports_file_id, 
	reports.run_id AS reports_run_id, 
	reports.bug_id AS reports_bug_id, 
	reports.checker_id AS reports_checker_id, 
	reports.checker_cat AS reports_checker_cat, 
	reports.bug_type AS reports_bug_type, 
	reports.severity AS reports_severity, 
	reports.line AS reports_line, 
	reports."column" AS reports_column, 
	reports.path_length AS reports_path_length, 
	reports.analyzer_name AS reports_analyzer_name, 
	reports.checker_message AS reports_checker_message, 
	reports.detection_status AS reports_detection_status, 
	reports.review_status AS reports_review_status, 
	reports.review_status_author AS reports_review_status_author, 
	reports.review_status_message AS reports_review_status_message, 
	reports.review_status_date AS reports_review_status_date, 
	reports.review_status_is_in_source AS reports_review_status_is_in_source, 
	reports.detected_at AS reports_detected_at, 
	reports.fixed_at AS reports_fixed_at, 
	files.filename AS files_filename 
FROM reports LEFT OUTER JOIN report_annotations ON                        <- ...only FROM reports.... 
	reports.id = report_annotations.report_id LEFT OUTER JOIN 
(SELECT anon_2.id AS id FROM 
	(SELECT max(reports.id) AS id, max(reports.severity) AS severity 
FROM reports LEFT OUTER JOIN files ON 
	reports.file_id = files.id 
		WHERE files.filepath LIKE %(filepath_1)s GROUP BY reports.bug_id) AS anon_2 
			ORDER BY anon_2.severity ASC 
LIMIT %(param_1)s OFFSET %(param_2)s) AS anon_1 ON anon_1.id = reports.id 
	LEFT OUTER JOIN files ON reports.file_id = files.id                      <- new outer join
WHERE anon_1.id IS NOT NULL

It is correctly showing the proper number of reports.

This is the original one:

SELECT 
	reports.id AS reports_id, 
	reports.file_id AS reports_file_id, 
	reports.run_id AS reports_run_id, 
	reports.bug_id AS reports_bug_id, 
	reports.checker_id AS reports_checker_id, 
	reports.checker_cat AS reports_checker_cat, 
	reports.bug_type AS reports_bug_type, 
	reports.severity AS reports_severity, 
	reports.line AS reports_line, 
	reports."column" AS reports_column, 
	reports.path_length AS reports_path_length, 
	reports.analyzer_name AS reports_analyzer_name, 
	reports.checker_message AS reports_checker_message, 
	reports.detection_status AS reports_detection_status, 
	reports.review_status AS reports_review_status, 
	reports.review_status_author AS reports_review_status_author, 
	reports.review_status_message AS reports_review_status_message, 
	reports.review_status_date AS reports_review_status_date, 
	reports.review_status_is_in_source AS reports_review_status_is_in_source, 
	reports.detected_at AS reports_detected_at, 
	reports.fixed_at AS reports_fixed_at, 
	files.filename AS files_filename 
FROM files, reports LEFT OUTER JOIN report_annotations ON       <- ...FROM files.... 
	reports.id = report_annotations.report_id LEFT OUTER JOIN 
(SELECT anon_2.id AS id FROM 
	(SELECT max(reports.id) AS id, max(reports.severity) AS severity 
FROM reports LEFT OUTER JOIN files ON 
	reports.file_id = files.id 
		WHERE files.filepath LIKE %(filepath_1)s GROUP BY reports.bug_id) AS anon_2 
			ORDER BY anon_2.severity ASC 
LIMIT %(param_1)s OFFSET %(param_2)s) AS anon_1 ON anon_1.id = reports.id 
WHERE anon_1.id IS NOT NULL

Produces lots of bogus outputs, where the report hashes are the same, and freezes client browsers:
image

The sane filter settings were used for both query printing which was:
uniqueing + a source_component filter
It seems like we had a descartes product in one of the subqueries, which we still need to restrict with a join.
I would be lying if I said I understood it completely, so discuss it.

One extra thing to note is the reports."column" AS reports_column, lines. I also don't know why these appear.

@vodorok vodorok requested a review from bruntib as a code owner April 18, 2023 12:45
@vodorok vodorok self-assigned this Apr 18, 2023
@vodorok vodorok force-pushed the filter_fix branch 3 times, most recently from e4fa2ec to c8f2f4c Compare April 19, 2023 09:52
@bruntib bruntib merged commit 2e57231 into Ericsson:master Apr 19, 2023
@whisperity
Copy link
Contributor

@vodorok Likely COLUMN is otherwise a keyword, and this is PostgreSQLese to escape from parsing it as a keyword, referring to a column literally named column instead.

@vodorok vodorok deleted the filter_fix branch May 22, 2023 11:47
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.

3 participants