mirror of
https://github.com/uptrace/go-clickhouse.git
synced 2025-06-06 23:16:18 +02:00
55 lines
881 B
Go
55 lines
881 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"github.com/uptrace/go-clickhouse/ch"
|
||
|
"github.com/uptrace/go-clickhouse/chdebug"
|
||
|
)
|
||
|
|
||
|
const query = `
|
||
|
SELECT
|
||
|
number
|
||
|
, randomString(25)
|
||
|
, array(1, 2, 3, 4, 5)
|
||
|
, now()
|
||
|
FROM system.numbers LIMIT 1000000
|
||
|
`
|
||
|
|
||
|
func benchmark(ctx context.Context, db *ch.DB) error {
|
||
|
rows, err := db.QueryContext(ctx, query)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for rows.Next() {
|
||
|
var (
|
||
|
col1 uint64
|
||
|
col2 string
|
||
|
col3 []uint8
|
||
|
col4 time.Time
|
||
|
)
|
||
|
if err := rows.Scan(&col1, &col2, &col3, &col4); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
ctx := context.Background()
|
||
|
|
||
|
db := ch.Connect(ch.WithDatabase("test"))
|
||
|
db.AddQueryHook(chdebug.NewQueryHook(
|
||
|
chdebug.WithEnabled(false),
|
||
|
chdebug.FromEnv(""),
|
||
|
))
|
||
|
|
||
|
start := time.Now()
|
||
|
if err := benchmark(ctx, db); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
fmt.Println(time.Since(start))
|
||
|
}
|