Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime ingest method is constantly updating sensor nodes needlessly #4

Open
caparker opened this issue Sep 27, 2022 · 0 comments
Open

Comments

@caparker
Copy link
Collaborator

Running the same file repeatedly will result in the sensor nodes being updated every time. And because there is a trigger on that table to records every update it means that we have a table (sensor_nodes_history) that is growing constantly for no reason.

Here is an example output from the ingest process

NOTICE:  total-measurements: 28850, deleted-timescaledb: 0, deleted-future-measurements: 1, deleted-past-measurements: <NULL>, from: 2018-01-01 00:00:00+00, to: 2022-09-26 03:00:00+00, inserted-from: <NULL>, inserted-to: <NULL>, updated-nodes: 3948, inserted-measurements: 0, inserted-measurands: 0, inserted-nodes: 0, rejected-nodes: 0, rejected-systems: 0, rejected-sensors: 0, exported-sensor-days: 0, process-time-ms: 3438.557, source: fetch

And here is the statement that is likely causing the issue. I have not debugged it yet

WITH updates AS (
UPDATE sensor_nodes s SET
    site_name = COALESCE(t.site_name, s.site_name),
    source_name = COALESCE(t.source_name, s.source_name),
    city = COALESCE(t.city, s.city),
    country = COALESCE(t.country, s.country),
    ismobile = COALESCE(t.ismobile, s.ismobile),
    metadata = COALESCE(s.metadata, '{}'::jsonb) || t.metadata,
    geom = COALESCE(t.geom, s.geom),
    modified_on = now()
FROM tempfetchdata_nodes t
WHERE t.sensor_nodes_id = s.sensor_nodes_id AND
(
    (s.geom IS NULL and t.geom IS NOT NULL)
OR

    ROW(
        t.sensor_nodes_id,
        t.ismobile,
        t.site_name,
        t.source_name,
        t.city,
        t.country,
        t.metadata
    ) IS DISTINCT FROM (
        s.sensor_nodes_id,
        s.ismobile,
        s.site_name,
        s.source_name,
        s.city,
        s.country,
        s.metadata
    )
)
RETURNING 1)
SELECT COUNT(1) INTO __updated_nodes
FROM updates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant