Repository navigation
Decision: truncate results with an explicit signal (exit code 5, V12N-Truncated) #22
CharmingGroot
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Background
Results are capped (default 10000 rows) and queries have a statement timeout (default 30 s). The SPARQL 1.1 Query Results JSON format has no way to mark a result as partial, so a truncated 10000-row result looks exactly like a complete one. Over HTTP the status line is sent before the body (RFC 9110), so once rows are streaming with 200 the status can no longer change.
Other engines differ: Virtuoso truncates and adds
X-SPARQL-MaxRows(even when the row count only equals the cap), GraphDB returns partial results without a marker by default, Fuseki and QLever answer a timeout before the first row with an HTTP error, Ontop has no row cap and returns 500 on timeout, and theontop queryCLI exits 0 on errors.Decision
v12n query): exit code 4 for a timeout, 5 for the row limit. On truncation stdout is a complete, valid result and stderr gets onewarning:line with the cause and the limit; a timeout that cuts output mid-stream writes anerror:line and leaves the JSON unclosed so it cannot be mistaken for a complete result.v12n serve): a truncated result is200withV12N-Truncated: <limit>(noX-prefix, RFC 6648); the header is absent on complete results. To know about truncation before the first byte, the query is wrapped withcount(*) OVER ()overLIMIT n+1, which makes PostgreSQL compute up to n+1 rows before the first row (bounded latency cost). A timeout before the first row is503; an error after streaming started aborts the response and is logged.V12N_DATABASE_URL,V12N_ROW_LIMIT,V12N_STATEMENT_TIMEOUT, …); unknownV12N_*names are ignored with a warning.References
배경
결과에는 상한(기본 10000행)이 있고 질의에는 statement timeout(기본 30초)이 있다. SPARQL 1.1 Query Results JSON 형식에는 부분 결과를 표시할 자리가 없어서, 잘린 10000행 결과와 완전한 10000행 결과가 똑같아 보인다. HTTP는 상태 줄을 본문보다 먼저 보내므로(RFC 9110), 200으로 행을 스트리밍하기 시작하면 상태를 바꿀 수 없다.
다른 엔진의 처리는 제각각이다. Virtuoso는 결과를 자르고
X-SPARQL-MaxRows를 붙인다(행 수가 상한과 같기만 해도 붙음). GraphDB는 기본 설정에서 부분 결과를 표시 없이 반환한다. Fuseki와 QLever는 첫 행 전 timeout에 HTTP 오류로 응답한다. Ontop은 행 상한이 없고 timeout에 500을 낸다.ontop queryCLI는 오류에도 종료 코드 0이다.결정
v12n query): timeout은 종료 코드 4, 행 상한은 5. 잘린 경우 stdout은 완전하고 올바른 결과이고, stderr에 원인과 상한을 담은warning:한 줄을 쓴다. 출력 도중 timeout이 나면error:한 줄을 쓰고, JSON을 닫지 않아 완전한 결과로 오인되지 않게 한다.v12n serve): 잘린 결과는200과V12N-Truncated: <상한>헤더(RFC 6648에 따라X-없음)로 응답하고, 완전한 결과에는 헤더를 붙이지 않는다. 첫 바이트 전에 잘림 여부를 알기 위해 질의를LIMIT n+1위에서count(*) OVER ()로 감싼다. 그 대가로 PostgreSQL이 첫 행 전에 최대 n+1행을 계산한다(지연 비용에 상한이 있음). 첫 행 전 timeout은503이고, 스트리밍 시작 뒤 오류는 응답을 끊고 로그에 남긴다.V12N_DATABASE_URL,V12N_ROW_LIMIT,V12N_STATEMENT_TIMEOUT등). 목록에 없는V12N_*는 경고와 함께 무시한다.참고
All reactions