Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 59851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:04:12+00:00 2026-05-10T18:04:12+00:00

I have around 3500 flood control facilities that I would like to represent as

  • 0

I have around 3500 flood control facilities that I would like to represent as a network to determine flow paths (essentially a directed graph). I’m currently using SqlServer and a CTE to recursively examine all the nodes and their upstream components and this works as long as the upstream path doesn’t fork alot. However, some queries take exponentially longer than others even when they are not much farther physically down the path (i.e. two or three segments ‘downstream’) because of the added upstream complexity; in some cases I’ve let it go over ten minutes before killing the query. I’m using a simple two-column table, one column being the facility itself and the other being the facility that is upstream from the one listed in the first column.

I tried adding an index using the current facility to help speed things up but that made no difference. And, as for the possible connections in the graph, any nodes could have multiple upstream connections and could be connected to from multiple ‘downstream’ nodes.

It is certainly possible that there are cycles in the data but I have not yet figured out a good way to verify this (other than when the CTE query reported a maximum recursive count hit; those were easy to fix).

So, my question is, am I storing this information wrong? Is there a better way other than a CTE to query the upstream points?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:04:13+00:00Added an answer on May 10, 2026 at 6:04 pm

    I know nothing about flood control facilities. But I would take the first facility. And use a temp table and a while loop to generate the path.

     — Pseudo Code TempTable (LastNode, CurrentNode, N)

    DECLARE @intN INT SET @intN = 1

    INSERT INTO TempTable(LastNode, CurrentNode, N) — Insert first item in list with no up stream items…call this initial condition SELECT LastNode, CurrentNode, @intN FROM your table WHERE node has nothing upstream

    WHILE @intN <= 3500 BEGIN SEt @intN = @intN + 1 INSERT INTO TempTable(LastNode, CurrentNode, N) SELECT LastNode, CurrentNode, @intN FROM your table WHERE LastNode IN (SELECT CurrentNode FROM TempTable WHERE N = @intN-1)

    IF @@ROWCOUNT = 0      BREAK 

    END

    If we assume that every node points to one child. Then this should take no longer than 3500 iterations. If multiple nodes have the same upstream provider then it will take less. But more importantly, this lets you do this…

    SELECT LastNode, CurrentNode, N FROM TempTable ORDER BY N

    And that will let you see if there are any loops or any other issues with your provider. Incidentally 3500 rows is not that much so even in the worst case of each provider pointing to a different upstream provider, this should not take that long.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched around, and it seems that this is a limitation in MS
I have around 400 GB Live mysql Databases on one server and I like
I have around 2 million strings with different lengths that I need to compress
I have around 1500 bytes of data that I want to construct a checksum
I have around 6-7 javascript files that I want to minify and combine. I
I have around 1000 pdf filesand I need to convert them to 300 dpi
I have around 25 worksheets in my workbook (Excel spreadsheet). Is there a way
I have around 8-9 parameters to pass in a function which returns an array.
I have around ~40 custom modules and a custom skin on a DotNetNuke site
Excuse me if I'm off on my terminology, I only have around 2.4 years

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.