# Increase in query time after I created a sharded key on one of the join columns

**URL:** <https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363>\
**Category:** Query Tuning\
**Tags:** developer\
**Created:** [August 27, 2025, 5:42pm UTC](https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363 "2025-08-27T17:42:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shanelobo18](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@shanelobo18](https://www.singlestore.com/forum/u/shanelobo18)\
**Post date:** [August 27, 2025, 5:42pm UTC](https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363/1 "2025-08-27T17:42:48Z")

</div>

Hi team,  
So I was using sample data from the employees table (from the s3 bucket singlestore-education/datasets/db\_employees/) and was tuning the below query  
SELECT e.first\_name, e.last\_name, d.dept\_name, t.title, t.from\_date, t.to\_date  
FROM employees e  
INNER JOIN dept\_emp de ON e.emp\_no=de.emp\_no  
INNER JOIN departments d ON de.dept\_no=d.dept\_no  
INNER JOIN titles t ON e.emp\_no=t.emp\_no  
ORDER BY e.first\_name, e.last\_name, d.dept\_name, t.from\_date  
LIMIT 10;

When there was no shard keys, it joins the employees with the titles and has an execution time of 358 ms.  
When I created another table titles\_sharded from the titles table and added the emp\_no column as a shard key. The join order changed and the query now takes 394 ms.  
I was curious as to why the sharding key didn’t make a slight difference as this there would be less shuffling of data between the leaf nodes.

---

<div class="post-metadata">

**Author:** ![hanson1](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson1/32/2092_2.png) [@hanson1](https://www.singlestore.com/forum/u/hanson1)\
**Post date:** [August 27, 2025, 11:10pm UTC](https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363/2 "2025-08-27T23:10:39Z")

</div>

That data set is probably small. Adding a shard key could make it try to prefer a collocated join and that might change the join order. You probably also are measuring compile time and not only execution time. Small changes like that are not usually significant for real workloads. If you wanted to thoroughly optimize a query like this, you should get a profile or debug profile for both queries and make sure profile was run twice to exclude compile time for each. Then look at that profile in the profile GUI in the cloud portal and see where the time is getting spent. Then try to drive down the time by appropriate choice of table type (rowstore vs. columnstore) sorting, sharding, and indexes. Our docs have discussion of when to use these.

E.g. go to [docs.singlestore.com](http://docs.singlestore.com) and ask SqRL this “find documentation on how to choose sort and shard keys when designing your physical table schema”

---

<div class="post-metadata">

**Author:** ![shanelobo18](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@shanelobo18](https://www.singlestore.com/forum/u/shanelobo18)\
**Post date:** [August 28, 2025, 2:23pm UTC](https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363/3 "2025-08-28T14:23:54Z")

</div>

Thank you for taking your time to answer my query. I did run the profile twice. The table does have data over 300K rows. Thank you for the SqRL tip, there was a lot of takeaways from the conversation. Adding a sort key on one side of the join eventually did cut the time by 1/4th. I was trying and testing query tuning across different databases to check the join order and I realized that plugging the table with shard keys provides the perfect join order.  
Once again, thank you for your time.

---

<div class="post-metadata">

**Author:** ![shanelobo18](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@shanelobo18](https://www.singlestore.com/forum/u/shanelobo18)\
**Post date:** [September 2, 2025, 8:04am UTC](https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363/4 "2025-09-02T08:04:13Z")

</div>

Hi team,  
I also wanted to know if its possible to pass hints to queries to alter the natural behavior of the query?

---

<div class="post-metadata">

**Author:** ![hanson1](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson1/32/2092_2.png) [@hanson1](https://www.singlestore.com/forum/u/hanson1)\
**Post date:** [September 15, 2025, 5:57pm UTC](https://www.singlestore.com/forum/t/increase-in-query-time-after-i-created-a-sharded-key-on-one-of-the-join-columns/8363/5 "2025-09-15T17:57:10Z")

</div>

We document the STRAIGHT JOIN hint and a few others. For a list of hints that are documented, go to

> **[SingleStore | Develop with SQrL, Your SingleStore Copilot.](https://www.singlestore.com/sqrl)**
>
> SingleStore helps businesses adapt more quickly, embrace diverse data and accelerate digital innovation by operationalizing all data through one platform.

and ask it “what query hints are available in SingleStore?”

We have some other hints that are only used for support and we don’t publicize them because they’re in general subject to change and not easy to use.
