<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by University of Washington Database Group on Medium]]></title>
        <description><![CDATA[Stories by University of Washington Database Group on Medium]]></description>
        <link>https://medium.com/@uwdb?source=rss-9a5cdffbbd25------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SdW5EgteHUTvu86wkKeMNg.jpeg</url>
            <title>Stories by University of Washington Database Group on Medium</title>
            <link>https://medium.com/@uwdb?source=rss-9a5cdffbbd25------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:00:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@uwdb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introducing PowerStation]]></title>
            <link>https://medium.com/@uwdb/introducing-powerstation-26c8b3a53191?source=rss-9a5cdffbbd25------2</link>
            <guid isPermaLink="false">https://medium.com/p/26c8b3a53191</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[University of Washington Database Group]]></dc:creator>
            <pubDate>Mon, 09 Jul 2018 19:32:55 GMT</pubDate>
            <atom:updated>2018-07-10T22:30:11.189Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever experienced going to a website that takes forever to load and wondered why? You are not alone. Even well-developed, popular web applications have performance issues. Some of these apps have pages that can take way more than 2 seconds to load, and this can easily <a href="https://webmasters.googleblog.com/2010/05/you-and-site-performance-sitting-in.html">“make or break” your website</a>. As you might have guessed, performance is one of the top most mentioned issues in many web applications’ bug tracking systems.</p><h3>Architecture of Web Applications</h3><p>To understand the causes of these performance issues, we need to understand how web apps are constructed on the server side. By far the most common is the<a href="https://www.sitepoint.com/model-view-controller-mvc-architecture-rails/"> model-view-controller architecture</a> implemented by many<a href="https://en.wikipedia.org/wiki/Object-relational_mapping"> object-relational mapping frameworks (ORMs)</a> (e.g., Rails, Django). The idea of ORMs is to free developers from needing to know how to talk to the database (often using a specialized language such as SQL) where their application data is stored, but instead allow developers to write their applications in general-purpose languages like Ruby or Python using the ORM APIs. During runtime, the ORM translates the API calls to SQL queries to manipulate persistent data stored in the backend databases. The retrieved data is then rendered and sent back to the client such as a browser.</p><p>Abstracting database operations into APIs written in the same language as the rest of the application is a good idea. However, this abstraction can also lead to problems: retrieving data from the database often takes 10 to even 10 million times longer than going to the main memory on the web server, and developers are no longer aware of which function call can turn into a long-running SQL query due to the ORM abstraction. There are many blog posts discussing various issues, including the infamous “N+1” problem (<a href="https://tideways.com/profiler/blog/5-doctrine-orm-performance-traps-you-should-avoid">[1]</a><a href="https://medium.com/@hansonkd/performance-problems-in-the-django-orm-1f62b3d04785">[2]</a><a href="https://www.infoq.com/articles/Rails-Performance">[3]</a>, to name a few). However, many of them seem anecdotal and we are unaware of any systematic study that looks into <em>what are the common performance issues in the wild and how prevalent they are</em>, and that’s what we set out to do.</p><h3>Studying Web Applications “in the Wild”</h3><p>To study this problem, we wanted to pick a single framework with a lot of apps that we can get access to easily. At the end, we selected the<a href="https://rubyonrails.org/"> Ruby on Rails ORM</a> due to its popularity and the number of open-source web apps that are available. We took 12 popular Rails web apps hosted on github and analyzed their source code. Among these we looked at the issues reported on their trackers, profiled their performance using synthetic data, and tried to fix any performance issues that we identified.</p><p><em>Spoiler alert: We found many performance issues that generalize across the applications. Many of them can be easily fixed and lead to substantial performance improvement.</em></p><h4>Identifying the issues</h4><p>The applications we chose covers many domains, from online forums, collaboration platforms, e-commerce, to task management, social networking, and map services. We picked the most-starred apps from each category. Many of them are well-known such as<a href="https://about.gitlab.com/"> Gitlab</a>,<a href="https://www.openstreetmap.org/"> OpenStreetMap</a>,<a href="https://diasporafoundation.org/"> Diaspora</a>, <a href="https://github.com/discourse/discourse">Discourse</a>, etc.</p><p>First, we manually sampled over 200 performance-related issues from 12 applications and summarized the common issues that users have reported. Next, we profiled the applications with synthetic data (using the same data distribution as reported by the app developers if available, and scaling the data up). We measured the page loading time for each application using their most recent version, and tried to identify the reasons for the slow ones. We have<a href="https://github.com/hyperloop-rails/powerstation"> also released the code</a> that we used for our study.</p><p>After examining these slow pages and the code that generates them, we summarize them into performance <em>anti-patterns</em><strong> </strong>— common code patterns that lead to bad performance. Altogether we found nine anti-patterns that are prevalent across the applications we studied.</p><p>First, some general observations.</p><p><em>Observation 1</em>: Most (11 out of 12) applications have at least one page that take <a href="https://webmasters.googleblog.com/2010/05/you-and-site-performance-sitting-in.html">more than 2 seconds</a> to load, and half of them have pages that take over 3 seconds. Many pages have both efficiency and scalability issues.</p><p><em>Observation 2</em>: Most of the time is spent on the server side. Especially for the slow-loading pages, on average over 80% of the time is spent on the server. This suggests that the causes for the slowdown is likely due to server side issues (rather than client side rendering, for instance).</p><p>After we identified these anti-patterns, we manually fixed them and re-evaluated the time taken to load pages. Interestingly enough, as shown in Figure 1, most fixes (over 80%) require fewer than 5 lines of code change, but they result in significant speedup in page load time (60% of the fixes has over 2x speedup)!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUQ3AuC85ZL7vEKdq6_MMQ.png" /><figcaption>Fig 1: Average speedup and average lines of code change for fixing one anti-pattern. Each bar represents one type of anti-pattern that is described in detail in <a href="https://hyperloop-rails.github.io/220-HowNotStructure.pdf">our ICSE paper</a>.</figcaption></figure><h4>Our “top 3 list” of anti-patterns</h4><ul><li><strong>API Misuses</strong></li></ul><p>Like many ORMs, Rails comes with many APIs. Some of them share similar functionality but have different performance characteristics. For example:</p><pre>@user.role_ids = Role.all.map{|r| r.id}<br>@user.role_ids = Role.all.pluck(:id)</pre><p>The above two lines do the same thing: return the id&#39;s of every role. However, Rails translates them into different SQL queries:</p><pre>SELECT * FROM roles<br>SELECT id FROM roles</pre><p>The second query is more efficient than the first since it only retrieves one of the attributes rather than everything (i.e., *), this is especially important when each role object contains many attributes. But ORM users are unlikely to know unless they look “underneath the covers.” Unfortunately, many other types of API misuses widely exist, and we have <a href="https://hyperloop-rails.github.io/220-HowNotStructure.pdf">summarized them</a> for both the Rails and Django ORM.</p><ul><li><strong>Unnecessary Computation</strong></li></ul><p>Due to abstraction, developers often are unaware of their code issuing multiple queries unnecessarily. For instance:</p><pre>values.each do |value|​<br>    read_only_attribute_names(user).include?value<br>end</pre><p>the code above issues one query per iteration to check if a user includes a value in their attributes. However, as user is unmodified, the entire loop can be replaced with one single query. This pattern is hard to spot, especially when the query is not directly issued in loop but in functions that are called in the loop.</p><ul><li><strong>Design Tradeoffs</strong></li></ul><p>Often times a simple webpage design / layout change can drastically impact performance. For instance,<a href="https://www.interaction-design.org/literature/article/split-the-contents-of-a-website-with-the-pagination-design-pattern"> pagination</a> is a common trick to accelerate webpage loading, i.e., render a long list of contents over multiple pages. However, we found that “rendering the entire laundry list” is still a common practice in the applications we studied, and using pagination can reduce loading time by over 90%.</p><p>Other tradeoffs we found include expensive but trivial content displayed on webpages, which turn out to have performance implications. For example, one social network application<a href="https://github.com/discourse/discourse/pull/4852"> used to show daily summary on a webpage</a>. Developers later found this feature to be too slow as the number of daily emails increased, and other summaries on the same page already provide similar information, so they removed this feature. Similar design decisions exist across different applications.</p><p>You can find out about the other patterns we have identified in<a href="https://hyperloop-rails.github.io/220-HowNotStructure.pdf"> our ICSE paper</a>.</p><h3>What’s Next?</h3><p>Now that we have manually identified these anti-patterns, we have built a new tool called <a href="https://hyperloop-rails.github.io/powerstation/">PowerStation</a> that can detect these anti-patterns for Rails application automatically. PowerStation is part of our <a href="https://hyperloop-rails.github.io/">Hyperloop</a> project for studying web apps and techniques for alleviating performance issues.</p><p><a href="https://hyperloop-rails.github.io/powerstation/">PowerStation</a> is a static analyzer that finds potential problematic code for your application. Many of the above anti-patterns can be identified statically, and our tool will point them out in the code. It can also automatically fix some of the issues above mentioned. PowerStation has been integrated into <a href="https://plugins.jetbrains.com/plugin/10604-powerstation">RubyMine</a>, a handy IDE for Rails developers. To use it, all you need to do is just load your app code and click a button. Our project page also includes a <a href="https://www.youtube.com/watch?v=bba_L0_IAuo&amp;feature=youtu.be">demo video</a> of its use.</p><h3>Using PowerStation</h3><p>Here’s a sample usage of PowerStation in fixing an API-misuse anti-pattern, as we mentioned in the previous example. PowerStation analyzes the code and highlights all inefficient API calls as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nVwbOFYwTnNWA6Zs" /><figcaption>Figure 2: Powerstation highlights the code that can cause performance issues</figcaption></figure><p>Then, when the user clicks the fix button, our tools makes a suggestion to replace the highlighted code with a better API:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WfNxPiPXAp2LqVn4" /><figcaption>Figure 3: Powerstation fixes the anti-pattern by replacing the inefficient API call with one that only returns one of the attributes from the objects.</figcaption></figure><p>This example actually comes from an application called <a href="https://github.com/drhenner/ror_ecommerce/blob/3db5a29000ac93d6b896469511004e450d019042/app/controllers/admin/overviews_controller.rb#L20">ror-ecommerce</a>, and PowerStation’s fix can result in a speedup of 8x for page loading (for 10K records in the roles table). We have more usage examples listed on <a href="https://hyperloop-rails.github.io/powerstation/docs/howtouse/">our website</a>.</p><h3>Learning more</h3><p>If you worry about your Rails app running slow, definitely try out PowerStation! We are still in the process of adding more features. If you find any common performance issues, feel free to contact us or submit feature requests on our <a href="https://github.com/hyperloop-rails/powerstation">github page</a>.</p><ul><li><a href="https://hyperloop-rails.github.io/">Main project website</a></li><li><a href="https://hyperloop-rails.github.io/powerstation/docs/install/">PowerStation installation instructions</a></li><li><a href="https://hyperloop-rails.github.io/docs/dockers/">Replication packages of our application study</a></li><li><a href="https://hyperloop-rails.github.io/people">Contact the authors</a></li><li><a href="https://news.ycombinator.com/item?id=17414383">Discussion on Hacker News</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26c8b3a53191" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Cosette]]></title>
            <link>https://medium.com/@uwdb/introducing-cosette-527898504bd6?source=rss-9a5cdffbbd25------2</link>
            <guid isPermaLink="false">https://medium.com/p/527898504bd6</guid>
            <category><![CDATA[verification]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[University of Washington Database Group]]></dc:creator>
            <pubDate>Wed, 19 Jul 2017 05:52:43 GMT</pubDate>
            <atom:updated>2017-09-03T05:46:53.906Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we are thrilled to announce our official 1.0 release of <a href="http://cosette.cs.washington.edu/">Cosette</a>, a SQL solver for <em>automatically checking semantic equivalences of SQL queries</em>. With Cosette, one can easily verify the correctness of SQL rewrite rules, find errors in buggy SQL rewrites, building auto-graders for SQL assignments, developing SQL optimizers, busting “fake SQLs,” etc.</p><h3>What is a SQL solver and what can it do?</h3><p>As a SQL solver, Cosette checks for <em>semantic equivalences</em> of SQL queries. Two SQL queries are semantically equivalent if they produce the same results given <em>any</em> valid input relations. Here is an example of two semantically equivalent SQL queries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*ME5f4fxQKZJTUU9ADrdosA.png" /></figure><p>These two queries will produce the exact same results no matter what the input relations <em>r</em> and <em>s</em> contain, and no matter what the predicate <em>p</em> is. So one can freely use one query for the other for any reason, e.g., improve query execution time, reduce amount of resources consumed, etc. Such rewrites form the basis of query optimization on modern database systems, such as MySQL, PostgreSQL, SQL Server, and [you name it], which all of us interact with (directly or indirectly) every day.</p><p>One would hope that all rewrites performed by database systems are indeed semantically preserving. Unfortunately, such rewrites are developed and checked by humans, and humans make mistakes. For example, can you decide if the following query Q3 is equivalent to the previous Q1?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*5XX16mJ-Dxt9mzRKCcIXIg.png" /></figure><p>Actually, they are not. We can show that Q3 is not equivalent to Q1 by the following counterexample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*yB6MBe27UTkULPVNbdY5nQ.png" /></figure><p>Now let’s check the results of Q1 and Q3 running on this counterexample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*5yoQ562nzHIS5OCrURlVYA.png" /></figure><p>Thus Q1 and Q3 are not equivalent.</p><p>The core idea of Cosette is to automate this process: <em>instead of reasoning about semantic equivalences manually, why not reason it using a computer program?</em> Turns out that reasoning SQL equivalences is a two-fold problem. Given two SQL queries, Cosette will do the following:</p><ol><li>If the two SQL queries are equivalent, Cosette will find a <em>mechanical proof</em> for the equivalence and validate it in using a Proof Assistant (currently Coq).</li><li>If the two SQL queries are inequivalent, Cosette will find a counterexample to show they are not equivalent. A counterexample is a set of specific input relation(s), where the two SQL queries will produce different results when executed using them, such as the one shown above.</li></ol><p>There might be very complex cases where Cosette cannot decide the equivalences within time and computation resource limits. In such cases, Cosette will need help from users in order to finish the proof or come up with a counterexample.</p><h3>Proving equivalences of SQL queries</h3><p>Cosette proves the semantic equivalences of SQL queries by compiling them to machine checkable mathematical representations (called <em>denotational semantics </em>in programming languages research) and then using simple mathematical principles to reason about them. Let’s take a look at how Cosette compiles the queries above.</p><p>One basic concept in databases is relation (aka tables). A relation is just a bag of tuples, and being a bag means that the order of tuples doesn’t matter. What matters is how many times (also called multiplicity) a given tuple appears in a relation. Cosette borrows this idea from database theory and compiles relations to mathematical functions that, given a tuple, returns the multiplicity of it in the relation (this is formally called a K-Relation, after <a href="http://users.ics.forth.gr/~gregkar/publications/pods2007.pdf">Green et al. PODS07</a>). For example, let’s suppose relation <em>r </em>contains 3 tuples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*35HkxWdnpBrzVpaONinXPA.png" /></figure><p>Notice that (“Alice”, 25) appears twice in the relation. Using the K-Relation representation, <em>r(t1) = r(t2) = 2</em>, and <em>r(t3) = 1</em>. For any other tuple <em>t</em>, we have <em>r(t) = 0</em>.</p><p>With this definition of a relation, a predicate is a function that returns either 0 or 1. For example, a predicate <em>x = 1 </em>returns 1 when applied to a tuple with attribute <em>x </em>equal to 1, or 0 otherwise. With all that in mind, a SQL query</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*UAFyrLMrwOlcFYF6NBQgFg.png" /></figure><p>is represented as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t15I_PpsmXqloFL_9azPpQ.png" /></figure><p>where <em>t </em>is a tuple.</p><p>Other SQL operators can be defined similarly. For example, the SQL bag union, <em>union all, </em>is simply defined as +, as the union of two bags means that the multiplicity of a tuple in the new relation is the sum of its multiplicities in the two input relations. Let’s look at the previous example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*6ptT2zwmvF4bSb8OYrHrgg.png" /></figure><p>Now here is the cool part: <em>by using the distributivity of * and +, we can prove that Q1 is equivalent to Q2 since we can make them syntactically equivalent!</em> This is how Cosette works internally. In addition, all the proofs are checked by a proof assistant called Coq. A proof assistant is a tool that checks the correctness of a proof mechanically. To learn more about how Coq (or proof assistants in general) works, check out this <a href="https://en.wikipedia.org/wiki/Four_color_theorem#Simplification_and_verification">lengthy proof of the four color theorem</a>, which is basically impossible to be check manually.</p><h3>Finding counterexamples</h3><p>You may ask, what if two SQL queries are not equivalent? We will never find a proof, right?</p><p>Indeed. However, since it might take a while (like, forever) for us to conclude that a proof doesn’t exist, it would be easier to show inequivalences by finding a <em>counterexample</em>. In Cosette, a counterexample is a set relations where the two queries will return different results when executed on them. Cosette search for such counterexamples using a <a href="https://en.wikipedia.org/wiki/Satisfiability_modulo_theories#SMT_solvers"><em>SMT solver</em></a>. The cool thing is, as a user, you don’t need to worry about how solvers work, since Cosette will compile SQL queries to the representations that a SMT solver can understand for you (just like how it compiles queries to K-Relations as shown above). Let’s look at an example. Assume you have two relations, <em>parts</em> with attributes <em>pnum</em> and <em>qoh</em>, and <em>supply </em>with attributes <em>pnum</em> and <em>shipdate</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*KzIzhXgOi_jIlwZWBfPhxA.png" /></figure><p>The above two queries were believed to be equivalent and were introduced as a clever rewrite rule in a database system in the 80’s. Three years afterwards, <a href="http://dl.acm.org/citation.cfm?id=38723">a researcher found that they are actually not equivalent</a> , since Q5 ignores the empty groups.</p><p>While it took database researchers 3 years to realize and fix the problem, it only took Cosette fewer than 3 seconds to find a counterexample for the queries above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*KrwD-YDn6GdMh3S0e7MBvw.png" /></figure><p>The above shows the counterexample that Cosette found: <em>supply</em> as an empty relation and <em>parts </em>as a relation with only one tuple (<em>pnum</em>:0, <em>qoh</em>:0). You can try this example in our <a href="https://demo.cosette.cs.washington.edu/">online demo</a> (select “Example: Count Bug” from the dropdown menu) and you will realize how this is indeed a counterexample that shows the falsity of the rewrite rule.</p><p>Pretty cool, eh?</p><h3>Learn and Use Cosette</h3><p>Now that you understand how Cosette works, you can start using it by:</p><ul><li>Reading <a href="http://cosette.cs.washington.edu/">The Cosette Guide</a>.</li><li>Playing with <a href="https://demo.cosette.cs.washington.edu/">Cosette online demo</a>.</li><li>Building your own applications using <a href="http://cosette.cs.washington.edu/guide#api">Cosette Web API</a>.</li><li>Subscribing to <a href="https://mailman.cs.washington.edu/mailman/listinfo/cosette">Cosette mailing list</a> and following us on <a href="https://twitter.com/uw_db">Twitter</a>.</li><li>Contributing to the <a href="https://github.com/uwdb/Cosette">project</a>.</li></ul><p>If you are a database researcher or hacker working on the next great SQL optimizer, get in touch with us to see how your system can become <br>“Cosette certified”!</p><p><em>This post was authored by </em><a href="http://shumochu.com/"><em>Shumo Chu</em></a><em>, </em><a href="http://homes.cs.washington.edu/~akcheung/"><em>Alvin Cheung</em></a><em>, and </em><a href="http://homes.cs.washington.edu/~suciu/"><em>Dan Suciu</em></a><em>. We would like to thank </em><a href="http://www.konne.me/"><em>Konstantin Weitz</em></a><em>, </em><a href="http://chenglongwang.org/"><em>Chenglong Wang</em></a><em>, </em><a href="https://www.linkedin.com/in/daniel-li-49729a77/"><em>Daniel Li</em></a><em>, and many other members from </em><a href="http://db.cs.washington.edu/"><em>the database group</em></a><em> and </em><a href="http://uwplse.org/"><em>the programming languages and software engineering group</em></a><em> at the University of Washington for their contributions and help.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=527898504bd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>