Skip to content

Commit

Permalink
Fix ch bug (#94)
Browse files Browse the repository at this point in the history
* fix qphH error and add placeholder

* add refresh-conn-wait for ch ap workload
  • Loading branch information
dbsid authored Dec 21, 2021
1 parent dfcd2b2 commit c3c6a49
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
44 changes: 22 additions & 22 deletions ch/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var queries map[string]string

const (
q1 = `
select ol_number,
/*PLACEHOLDER*/ /*q1*/select ol_number,
sum(ol_quantity) as sum_qty,
sum(ol_amount) as sum_amount,
avg(ol_quantity) as avg_qty,
Expand All @@ -15,7 +15,7 @@ where ol_delivery_d > '2007-01-02 00:00:00.000000'
group by ol_number order by ol_number;
`
q2 = `
select s_suppkey, s_name, n_name, i_id, i_name, s_address, s_phone, s_comment
/*PLACEHOLDER*/ /*q1*/select s_suppkey, s_name, n_name, i_id, i_name, s_address, s_phone, s_comment
from item, supplier, stock, nation, region,
(select s_i_id as m_i_id,
min(s_quantity) as m_s_quantity
Expand All @@ -36,7 +36,7 @@ where i_id = s_i_id
order by n_name, s_name, i_id;
`
q3 = `
select ol_o_id, ol_w_id, ol_d_id,
/*PLACEHOLDER*/ /*q3*/select ol_o_id, ol_w_id, ol_d_id,
sum(ol_amount) as revenue, o_entry_d
from customer, new_order, orders, order_line
where c_state like 'a%'
Expand All @@ -54,7 +54,7 @@ group by ol_o_id, ol_w_id, ol_d_id, o_entry_d
order by revenue desc, o_entry_d;
`
q4 = `
select o_ol_cnt, count(*) as order_count
/*PLACEHOLDER*/ /*q4*/select o_ol_cnt, count(*) as order_count
from orders
where
o_entry_d >= '2007-01-02 00:00:00.000000'
Expand All @@ -69,7 +69,7 @@ group by o_ol_cnt
order by o_ol_cnt;
`
q5 = `
select n_name,
/*PLACEHOLDER*/ /*q5*/select n_name,
sum(ol_amount) as revenue
from customer, orders, order_line, stock, supplier, nation, region
where c_id = o_c_id
Expand All @@ -89,15 +89,15 @@ where c_id = o_c_id
group by n_name;
`
q6 = `
select sum(ol_amount) as revenue
/*PLACEHOLDER*/ /*q6*/select sum(ol_amount) as revenue
from order_line
where
ol_delivery_d >= '1997-01-01 00:00:00'
and ol_delivery_d < '2030-01-01 00:00:00'
and ol_quantity between 1 and 100000;
`
q7 = `
select s_nationkey as supp_nation,
/*PLACEHOLDER*/ /*q7*/select s_nationkey as supp_nation,
substr(c_state,1,1) as cust_nation,
extract(year from o_entry_d) as l_year,
sum(ol_amount) as revenue
Expand All @@ -123,7 +123,7 @@ group by s_nationkey, substr(c_state,1,1), extract(year from o_entry_d)
order by s_nationkey, cust_nation, l_year;
`
q8 = `
select extract(year from o_entry_d) as l_year,
/*PLACEHOLDER*/ /*q8*/select extract(year from o_entry_d) as l_year,
sum(case when n2.n_name = 'INDIA' then ol_amount else 0 end) / sum(ol_amount) as mkt_share
from item, supplier, stock, order_line, orders, customer, nation n1, nation n2, region
where i_id = s_i_id
Expand All @@ -148,7 +148,7 @@ group by extract(year from o_entry_d)
order by l_year;
`
q9 = `
select n_name, extract(year from o_entry_d) as l_year, sum(ol_amount) as sum_profit
/*PLACEHOLDER*/ /*q9*/select n_name, extract(year from o_entry_d) as l_year, sum(ol_amount) as sum_profit
from item, stock, supplier, order_line, orders, nation
where ol_i_id = s_i_id
and ol_supply_w_id = s_w_id
Expand All @@ -163,7 +163,7 @@ group by n_name, extract(year from o_entry_d)
order by n_name, l_year desc;
`
q10 = `
select c_id, c_last, sum(ol_amount) as revenue, c_city, c_phone, n_name
/*PLACEHOLDER*/ /*q10*/select c_id, c_last, sum(ol_amount) as revenue, c_city, c_phone, n_name
from customer, orders, order_line, nation
where c_id = o_c_id
and c_w_id = o_w_id
Expand All @@ -178,7 +178,7 @@ group by c_id, c_last, c_city, c_phone, n_name
order by revenue desc;
`
q11 = `
select s_i_id, sum(s_order_cnt) as ordercount
/*PLACEHOLDER*/ /*q11*/select s_i_id, sum(s_order_cnt) as ordercount
from stock, supplier, nation
where mod((s_w_id * s_i_id),10000) = s_suppkey
and s_nationkey = n_nationkey
Expand All @@ -193,7 +193,7 @@ having sum(s_order_cnt) >
order by ordercount desc;
`
q12 = `
select o_ol_cnt,
/*PLACEHOLDER*/ /*q12*/select o_ol_cnt,
sum(case when o_carrier_id = 1 or o_carrier_id = 2 then 1 else 0 end) as high_line_count,
sum(case when o_carrier_id <> 1 and o_carrier_id <> 2 then 1 else 0 end) as low_line_count
from orders, order_line
Expand All @@ -206,7 +206,7 @@ group by o_ol_cnt
order by o_ol_cnt;
`
q13 = `
select c_count, count(*) as custdist
/*PLACEHOLDER*/ /*q13*/select c_count, count(*) as custdist
from (select c_id, count(o_id) as c_count
from customer left outer join orders on (
c_w_id = o_w_id
Expand All @@ -218,20 +218,20 @@ group by c_count
order by custdist desc, c_count desc;
`
q14 = `
select 100.00 * sum(case when i_data like 'PR%' then ol_amount else 0 end) / (1+sum(ol_amount)) as promo_revenue
/*PLACEHOLDER*/ /*q14*/select 100.00 * sum(case when i_data like 'PR%' then ol_amount else 0 end) / (1+sum(ol_amount)) as promo_revenue
from order_line, item
where ol_i_id = i_id and ol_delivery_d >= '2007-01-02 00:00:00.000000'
and ol_delivery_d < '2030-01-02 00:00:00.000000';
`
q15 = `
select s_suppkey, s_name, s_address, s_phone, total_revenue
/*PLACEHOLDER*/ /*q15*/select s_suppkey, s_name, s_address, s_phone, total_revenue
from supplier, revenue1
where s_suppkey = supplier_no
and total_revenue = (select max(total_revenue) from revenue1)
order by s_suppkey;
`
q16 = `
select i_name,
/*PLACEHOLDER*/ /*q16*/select i_name,
substr(i_data, 1, 3) as brand,
i_price,
count(distinct (mod((s_w_id * s_i_id),10000))) as supplier_cnt
Expand All @@ -246,7 +246,7 @@ group by i_name, substr(i_data, 1, 3), i_price
order by supplier_cnt desc;
`
q17 = `
select sum(ol_amount) / 2.0 as avg_yearly
/*PLACEHOLDER*/ /*q17*/select sum(ol_amount) / 2.0 as avg_yearly
from order_line, (select i_id, avg(ol_quantity) as a
from item, order_line
where i_data like '%b'
Expand All @@ -256,7 +256,7 @@ where ol_i_id = t.i_id
and ol_quantity < t.a;
`
q18 = `
select c_last, c_id o_id, o_entry_d, o_ol_cnt, sum(ol_amount)
/*PLACEHOLDER*/ /*q18*/select c_last, c_id o_id, o_entry_d, o_ol_cnt, sum(ol_amount)
from customer, orders, order_line
where c_id = o_c_id
and c_w_id = o_w_id
Expand All @@ -269,7 +269,7 @@ having sum(ol_amount) > 200
order by sum(ol_amount) desc, o_entry_d
`
q19 = `
select sum(ol_amount) as revenue
/*PLACEHOLDER*/ /*q19*/select sum(ol_amount) as revenue
from order_line, item
where (
ol_i_id = i_id
Expand All @@ -295,7 +295,7 @@ where (
);
`
q20 = `
select s_name, s_address
/*PLACEHOLDER*/ /*q20*/select s_name, s_address
from supplier, nation
where s_suppkey in
(select mod(s_i_id * s_w_id, 10000)
Expand All @@ -313,7 +313,7 @@ where s_suppkey in
order by s_name;
`
q21 = `
select s_name, count(*) as numwait
/*PLACEHOLDER*/ /*q21*/select s_name, count(*) as numwait
from supplier, order_line l1, orders, stock, nation
where ol_o_id = o_id
and ol_w_id = o_w_id
Expand All @@ -334,7 +334,7 @@ group by s_name
order by numwait desc, s_name;
`
q22 = `
select substr(c_state,1,1) as country,
/*PLACEHOLDER*/ /*q22*/select substr(c_state,1,1) as country,
count(*) as numcust,
sum(c_balance) as totacctbal
from customer
Expand Down
10 changes: 9 additions & 1 deletion ch/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
QueryNames []string
CreateTiFlashReplica bool
AnalyzeTable analyzeConfig
RefreshConnWait time.Duration
}

type chState struct {
Expand Down Expand Up @@ -183,6 +184,13 @@ func (w Workloader) Run(ctx context.Context, threadID int) error {
s := w.getState(ctx)
defer w.updateState(ctx)

if err := s.Conn.PingContext(ctx); err != nil {
time.Sleep(w.cfg.RefreshConnWait) // I feel it silly to sleep, but don't come up with better idea
if err := s.RefreshConn(ctx); err != nil {
return err
}
}

queryName := w.cfg.QueryNames[s.queryIdx%len(w.cfg.QueryNames)]
query := queries[queryName]

Expand Down Expand Up @@ -243,7 +251,7 @@ func (w Workloader) OutputStats(ifSummaryReport bool) {
if !m.Empty() {
r := m.GetInfo()
count += r.Count
elapsed = r.Elapsed
elapsed += r.Elapsed
}
}
if elapsed != 0 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/go-tpc/ch_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"strings"
"sync"
"time"

"github.com/spf13/cobra"

Expand All @@ -28,6 +29,7 @@ func registerCHBenchmark(root *cobra.Command) {
"queries",
"q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15,q16,q17,q18,q19,q20,q21,q22",
"All queries")
cmd.PersistentFlags().DurationVar(&chConfig.RefreshConnWait, "refresh-conn-wait", 5*time.Second, "duration to wait before refreshing sql connection")

var cmdPrepare = &cobra.Command{
Use: "prepare",
Expand Down

0 comments on commit c3c6a49

Please sign in to comment.