Monthly Archives: August 2020

Query Rewrite

I didn’t post anything about optimization for a while, so I decided to write a short follow-up on one discussion I recently had. 

I want to highlight today that when it comes to Postgres, it has the best optimizer ever. Most of the time, the only and the best thing a SQL developer can do are to allow the query planner to do its job. 

Anybody who writes SQL knows that any optimizer tries to choose the best execution plan for a query. Still, the common assumption is that “the best execution plan” means choosing the right index to use, or not to use indexes altogether. 

This assumption leaves out of consideration two essential steps. First, the query rewrite happens before any cost-based optimization is performed. One of the things that happen on that stage is replacing views with their SQL code. One of the biggest misconceptions which SQL textbooks introduce is that “you can use a view the same way as a table.” This by itself can potentially block the optimizer capabilities, since the total number of joins may easily exceed join_collapse_limit. Views with “group by” present even more problems, but enough about views. As I said multiple times, I hate views :).  

Another subject of rewriting is eliminating subqueries. This is another example of what people often forget. Consciously or subconsciously, but people often believe that when they write something like 

SELECT * FROM loan WHERE loan_id IN (….) 

whatever is IN(…) will be executed first. It won’t. This subquery will be rewritten into a JOIN, and then optimized according to the cost-based rules. 

And finally the last misconception of a similar kind. No matter how many times we say that the order of joins is not determined by the order the tables appear in the SELECT statement, there is an internal belief that by default, Postgres follows that order. It does not. The only time it does it when the number of tables exceeds the join_collapse_limit parameter. Moreover, for the same SELECT with different selection criteria, the order of joins may be different. 

The conclusion is my usual one: always try to clearly specify what you need, and check the execution plan. You may be surprised 🙂

Leave a comment

Filed under SQL

Please Help Us to Win!

Dear friends and colleagues! Do you remember the same time in 2019? Do you remember how I asked you to vote for me and to help me win the “Technologist of the Year” award? Ok, it case you don’t remember – Here is my last year call for support. and here is a my victory post – thanks for all of your support, I won the nomination, the first female in the history of this award.

Now, it’s time to vote again, this time – for our amazing CEO Stephanie Klein who was nominated as a finalist for the Outstanding Tech CEO Award! Let me tell you – she should win!

She has a vision, she is not afraid of challenges. She thinks big. And most importantly, she really values each and a single employee of Braviant Holdings.

I’ve being in IT for thirty-seven years, and each CEO says that people are the most important part of the company, but very few execute on that statement, and Stephanie is one of these few.

I won’t be able to achieve what I have achieved without her continuous support, and if you voted for me last year, you should vote for her. If you click to play my 2-minute acceptance speech from the last year award ceremony, you will know why:).

Please help her to win – vote here!

1 Comment

Filed under events, People

Critical Race Theory in HCI

Last week, I attended one of the meetups of the Chicago local ACM Chapter. ACM has several SIGs – Special Interest Groups, and technically speaking, I am a part of only one of them: SIGMOD (Management of Data) and also a member of ACM-W – Women in Computing. 

“Before all this started” (everybody these days have to say this, referring to our previous life), so – before it all started, I attended some of the ACM meetups, but not that often. 

The Chicago local chapter of ACM SIGCHI – Computer-Human Interaction – is something outside my area of interest, but I started to attend their virtual events and became more and more interested, and now I want to share it with my network :). 

The topic of the last week’s meetup was  “Critical Race Theory For HCI”, and I regret I didn’t publicize this event! It was so-so-so worth attending!

I am going to cite one example which started this presentation, and you will see what I am talking about. 

Here is the situation. A child is doing a project about a family vacation. If you would google images for “family vacation,” you will see the images of white families on exotic beaches. And it will take you, they said, six pages scrolling to get to the first picture of a non-white family. And if you refine your search with specifying “black family,” you will get pictures with a very different type of vacation. And you might need to refine your search even more. 

This picture is bad enough, especially because when you hear that, you realize right away that it’s true! And you just never thought about it. Well, maybe you did, but I didn’t!  

Afterward, there was a conversation about what can be done to change things and how we can all make it better in technical aspects and personnel management. And I think that was the most important take-away: do not let yourself off guard. Keep questioning yourself. 

And, if this all sounded interesting – consider joining this meetup!

1 Comment

Filed under events, talks