Skip to content

Commit 1c1c781

Browse files
committed
Additional perf test with complex SELECT statement
1 parent b802565 commit 1c1c781

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"test:sqlite": "jest --config test/config/sqlite.json",
3030
"test": "yarn generate && yarn test:bigquery && yarn test:mysql && yarn test:sqlite",
3131
"perf:big": "yarn ts-node perf/perf-test.ts big",
32-
"perf:func": "yarn ts-node perf/perf-test.ts func"
32+
"perf:func": "yarn ts-node perf/perf-test.ts func",
33+
"perf:select": "yarn ts-node perf/perf-test.ts select"
3334
},
3435
"devDependencies": {
3536
"@types/benchmark": "^2.1.2",

perf/data-select.sql

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
WITH
2+
FullAlbum AS (
3+
SELECT
4+
AlbumId,
5+
Album.Title AS AlbumName,
6+
Artist.ArtistId AS ArtistId,
7+
Artist.Name as ArtistName
8+
FROM
9+
Album
10+
LEFT JOIN Artist ON Album.ArtistId = Artist.ArtistId
11+
),
12+
FullTrack AS (
13+
SELECT
14+
TrackId,
15+
Track.Name AS TrackName,
16+
AlbumId,
17+
MediaType.Name AS Media,
18+
Genre.Name AS Genre,
19+
Composer,
20+
Milliseconds,
21+
Bytes,
22+
UnitPrice
23+
FROM
24+
Track
25+
LEFT JOIN MediaType USING (MediaTypeId)
26+
LEFT JOIN Genre USING (GenreId)
27+
),
28+
ArtistTrackCount AS (
29+
SELECT
30+
ArtistId,
31+
ArtistName,
32+
COUNT(TrackId) AS TrackCount
33+
FROM
34+
FullAlbum
35+
LEFT JOIN FullTrack USING (AlbumId)
36+
GROUP BY
37+
ArtistId
38+
ORDER BY
39+
TrackCount DESC,
40+
ArtistName ASC
41+
),
42+
ArtistPlaylistCount AS (
43+
SELECT
44+
ArtistId,
45+
ArtistName,
46+
COUNT(DISTINCT PlaylistId) AS PlaylistCount
47+
FROM
48+
FullAlbum
49+
LEFT JOIN Track USING (AlbumId)
50+
LEFT JOIN PlaylistTrack USING (TrackId)
51+
GROUP BY
52+
ArtistId
53+
ORDER BY
54+
PlaylistCount DESC,
55+
ArtistName ASC
56+
)
57+
SELECT
58+
ArtistTrackCount.ArtistName AS ArtistName,
59+
TrackCount,
60+
PlaylistCount,
61+
TrackCount / PlaylistCount AS TracksPerPlaylist
62+
FROM
63+
ArtistTrackCount
64+
LEFT JOIN ArtistPlaylistCount USING (ArtistId)
65+
ORDER BY
66+
TracksPerPlaylist DESC,
67+
TrackCount DESC,
68+
PlaylistCount DESC
69+
LIMIT
70+
15;

perf/perf-test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ function createTestData(variant: string) {
2525
mysql: getTestData("mysql"),
2626
bigquery: getTestData("bigquery"),
2727
};
28+
} else if (variant === "select") {
29+
return {
30+
sqlite: getTestData("select"),
31+
mysql: getTestData("select"),
32+
bigquery: getTestData("select"),
33+
};
2834
} else {
2935
throw new Error(`Unknown test data variant: ${variant}`);
3036
}

0 commit comments

Comments
 (0)