perkolatte opened a new pull request, #71111:
URL: https://github.com/apache/doris/pull/71111

   ### Background
   
   dbt-doris builds the new rows of an incremental model, and of the 
`partition` materialization, in a `<model>__dbt_tmp` table, inserts them into 
the model's table, and drops the temporary table at the end of the run. Doris 
auto analyze queues tables for statistics collection: once a minute it scans 
every internal table, and it also queues tables that queries read. Each table 
can opt out with the `auto_analyze_policy` property (#39532).
   
   ### What problem does this PR solve?
   
   Issue Number: close #70737
   Related PR: #39532 (added `auto_analyze_policy`)
   PR Type: Enhancement
   
   Problem Summary:
   
   When auto analyze queues a `__dbt_tmp` table and dbt drops it before the job 
runs, the FE logs `Failed to analyze table <model>__dbt_tmp` with a stack 
trace. The reporter sees about 1,000 of these a day from 40 hourly models. This 
PR makes the adapter run `ALTER TABLE <tmp> SET ("auto_analyze_policy" = 
"disable")` right after it creates a temporary table. A project var turns this 
off for Doris versions without the property. The model's own table keeps its 
settings.
   
   ### Details
   
   - **Before and after:** before, the temporary table has the default policy 
and auto analyze can queue it. After, it is set to `disable` right after it is 
created, before dbt inserts its rows into the model's table, so the appender's 
`needAnalyzeColumn()` check skips it from then on.
   - **Configs and defaults:** new project var 
`doris_disable_auto_analyze_on_temp_tables`, default `true`. Doris before 2.1.9 
and 3.0.3 rejects the property, so users of those versions set it to `false`.
   - **Impact on existing users:** models and their tables are unchanged. On 
Doris versions before 2.1.9 and 3.0.3, incremental and `partition` runs fail on 
the new `ALTER TABLE` until the var is set to `false`; the README says so.
   
   ### Testing
   
   - `TestDorisIncrementalTmpTableSkipsAutoAnalyze` (new): runs an append model 
twice and checks the debug log for the `ALTER TABLE ... __dbt_tmp SET 
("auto_analyze_policy" = "disable")` statement, and that the model's table has 
no `auto_analyze_policy`. It fails without the macro change (no `ALTER` in the 
log) and passes with it. `TestDorisIncrementalTmpTableAutoAnalyzeVarOff` (new) 
checks that the var turns the statement off.
   - The 35 tests under `test/functional/adapter` pass locally with dbt-core 
1.12.7 against `apache/doris:all-in-one-4.1.5`.
   - Manual run on the same container: an append model with `post_hook="select 
sleep(70)"`, so that the temporary table outlives a low-priority scan. In 2 
runs without this change, the collector picked up `events__dbt_tmp` both times 
(`Table events__dbt_tmp row count is not fully reported, skip auto analyzing 
it.`). In 2 runs with it, the collector never mentioned the table.
   
   ### Notes for Reviewers
   
   - The issue suggested setting the property in the `CREATE TABLE ... AS 
SELECT`. Doris rejects that (`Unknown properties: 
{auto_analyze_policy=disable}` on 4.1.5); it accepts the property only in 
`ALTER TABLE`, so the adapter alters the table after creating it.
   - Only relations created with `temporary=True` are altered. The incremental 
`__dbt_backup` table and the `table` materialization's intermediate relation 
become the model's table through `exchange_relation` (`REPLACE WITH TABLE`), so 
altering them would turn auto analyze off for the model itself.
   - Not covered: the table exists while the `CREATE TABLE ... AS SELECT` loads 
its rows, before the `ALTER` runs. A scan in that window can still queue it. 
Closing that window would need an FE change, such as 
`StatisticsAutoCollector.collect()` skipping a table that was dropped after it 
was queued without logging a warning. That is not part of this PR.
   
   ### Release note
   
   dbt-doris now turns off auto analyze on the temporary `__dbt_tmp` tables it 
creates, so the FE no longer logs auto analyze failures for them. On Doris 
versions before 2.1.9 and 3.0.3, set the 
`doris_disable_auto_analyze_on_temp_tables` var to `false`.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Partially verified: not run against Doris 2.1, 3.0, 
or 3.1, where the reporter saw the error
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, this description
   - Human review: not stated
   - Prompts: The author asked for unclaimed Doris issues to work on and chose 
#70737.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to