# query over segments

**URL:** <https://forum.kx.com/t/query-over-segments/9133>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [October 7, 2014, 2:01pm UTC](https://forum.kx.com/t/query-over-segments/9133 "2014-10-07T14:01:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavel\_hejbal](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pavel\_hejbal](https://forum.kx.com/u/pavel_hejbal)\
**Post date:** [October 7, 2014, 2:01pm UTC](https://forum.kx.com/t/query-over-segments/9133/1 "2014-10-07T14:01:00Z")

</div>

Hi All,

&nbsp;

I havepartitioned (by date), splayed and segmented (by exchange) database. Very oftenI have query like this:

&nbsp;

Select from t where date = 2014.07.01, market = xyz

&nbsp;

Where xyzmarket is part of specific exchange. The execution of this query is decomposedfor each segment, but only one is the right one, so the perf of the query isvery bad.

&nbsp;Ihave parted attribute on market, but it doesnt help a lot, because it stillsearch in each segment, and the query is very slow. I can &nbsp;add slaves forthe q process, so the subqueries on each segment &nbsp;will run parallely, butits not nice and efficient solution (I have more segments than licensedcores).

Thismodification of the query:

&nbsp;

select from`$“:/…/rightSegmentName/2014.07.01/t” where market = m

&nbsp;

runs muchfaster. So I can write a new function select2, which composed and execute thisfaster query (this function needs a dictionary where key is market and value issegment). Any other idea? I dont want to leave the segment setup, because ofother aspect.

&nbsp;

Thanks!

&nbsp;

Pavel
