What you should draw your attention to are the COST values. While these are arbitrary, they are not meaningless. Find the section of the query where this grows the largest, that is the slowest part of the query in need of optimization. (Save yourself some time as search for other_publisher_views) As this query had been previously reviewed for proper indexing, all queries should be indexed so we need to find another optimization. Since this is already indexed, draw your attention to the ROWS

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What you should draw your attention to are the COST values. While these are arbitrary, they are not meaningless. Find the section of the query where this grows the largest, that is the slowest part of the query in need of optimization. (Save yourself some time as search for other_publisher_views) As this query had been previously reviewed for proper indexing, all queries should be indexed so we need to find another optimization.

Since this is already indexed, draw your attention to the ROWS returned. If you look at the next query which makes use of these results, you'll notice the ROWS is much smaller. So our problem is we are looking at way more data than we need to. We are pulling over 100,000 rows when we are trying to find 4 of them.

Now let's extract the critical section to work with, along with simplified versions of its dependencies:

WITH
listing_info_raw AS (
    SELECT
      '' AS property_id_sha,
      '' AS mc_export_property_id_sha,
      '(Rental)' AS pretty_address,
    ' (Rental)' AS display_address
    ),
    periods AS (
    SELECT
      true AS is_current_period,
      CAST('2020-11-09' AS date) AS start_date,
      CAST('2020-11-15' AS date) AS end_date
    ),
         other_publisher_views AS (
             SELECT clv.date,
                    clv.streeteasy_page_views,
                    clv.trulia_page_views,
                    clv.zillow_page_views,
                    clv.realtor_page_views
             FROM agent_insights_lt.agent_insights__combined_listing_views AS clv
                      JOIN listing_info_raw ON clv.property_id_sha = listing_info_raw.property_id_sha
         ),
         other_publisher_views_by_period AS (
             SELECT is_current_period,
                    start_date,
                    end_date,
                    coalesce(sum(streeteasy_page_views), 0) AS streeteasy_page_views,
                    coalesce(sum(trulia_page_views), 0)     AS trulia_page_views,
                    coalesce(sum(zillow_page_views), 0)     AS zillow_page_views,
                    coalesce(sum(realtor_page_views), 0)    AS realtor_page_views
             FROM periods
                      LEFT JOIN other_publisher_views ON
                 other_publisher_views.date BETWEEN periods.start_date AND periods.end_date
)
SELECT * FROM other_publisher_views_by_period;

The task for this lab is to optimize this section of the query, which includes other_publisher_views & other_publisher_views_by_period.

Submit your optimized version of this section of the query.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
SQL Query
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education