LO_7.0.2.2, HSQLDB embedded & registered, Windows10_64bit
My query contains 3 nested sub-queries. Runtimes are ok, besides the very last nesting.
query_1 Runtime: < 1 sec
query_2(query_1) Runtime: < 1 sec
query_3(query_2(query_1) Runtime: ~ 1 sec
query_4(query_3(query_2(query_1) Runtime: < 7 min 30 sec
By “Runtime” I mean: Time from dbl-clicking the saved query icon to the time when the result is displayed.
QUESTION:
Is there a more efficient way of writing the query, so it runs faster and still return the same record set?
DETAILS:
1.) Create Table Definition for linked data-text-file.csv
CREATE TEXT TABLE "DOE-004" ("Recorded Time" VARCHAR(20), "Sampled Time" VARCHAR(20), "Pressure" VARCHAR(20), "Temperature" VARCHAR(20)
Menu/View/Refresh Tables ==> the new table is now showing up in tables container with the little squared-arrow logo
2.) Now link data-text-file.csv in same dir of this_LO_base.odb
SET TABLE "DOE-004" SOURCE "pressDataTest1.CSV;ignore_first=true;encoding=UTF-8";
- Note: Data in this file is messy, column alignment parses fine, but fields can contain numbers, &/or text (see query_1 below)
- The data-text-file.csv does not contain an index column, the 1st column contains a whacky timestamp, and with several header rows.
Saved query_1:
SELECT "Pressure" FROM "DOE-004" WHERE "Pressure" < 'A'
- Runtime: Less than one second
- Returns: 1019 records
- Purpose: get all the pressure records which begin with a number, ignore records beginning with letters
Saved Query_2: (contains nested query_1)
SELECT MAX( "Pressure" ) FROM
( SELECT "Pressure" FROM "DOE-004" WHERE "Pressure" < 'A' )
- Runtime: Less than one second
- Returns: 1 record
- Purpose: get record with maximum pressure record. NOTE: This max value can occur several times with different corresponding timestamps
Saved Query_3: (contains nested query_1, query_2)
SELECT MAX( "Recorded Time" ) FROM "DOE-004" WHERE "Pressure" =
( SELECT MAX( "Pressure" ) FROM
( SELECT "Pressure" FROM "DOE-004" WHERE "Pressure" < 'A' )
)
- Runtime: around one second
- Returns: 1 record
- Purpose: get record with the latest timestsamp at maximum pressure record.
- NOTE: Max pressure is likely to occur at several non-consecutive timestamps.
Saved Query_4: (contains nested query_1, query_2, query_3)
SELECT "Recorded Time", "Sampled Time", "Pressure", "Temperature"
FROM "DOE-004" WHERE "Recorded Time" =
( SELECT MAX( "Recorded Time" ) FROM "DOE-004" WHERE "Pressure" =
( SELECT MAX( "Pressure" ) FROM
( SELECT "Pressure" FROM "DOE-004" WHERE "Pressure" < 'A' )
)
)
- Runtime: 7 minutes and 30 seconds
- Returns: 1 record with “Recorded Time”, “Sampled Time”, “Pressure”, “Temperature” at max pressure at its latest occurrence.
- Purpose: get record with the latest timestsamp at maximum pressure record.
- NOTE: Max pressure is likely to occur at several non-consecutive timestamps.
- NOTE: This is the record set I actually want to extract.