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

  • SEARCH
  • Home
  • 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 6169789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:55:00+00:00 2026-05-23T22:55:00+00:00

Development language and DB: PHP/MySQL I have a table geo_places with something like 8

  • 0

Development language and DB: PHP/MySQL

I have a table geo_places with something like 8 million geographical locations.

These places are all hierarchical, and I use

  • parent_id (adjacency),
  • lft/rgt (nested set)
  • and ancestry (enumerated).

Now, I have “points of interest” table called entities which are assigned to a geographical location, and I record against each entity the:

  • lft value of the location in the geo_places
  • and the actual ID of the geographical location.

Now I need a way to provide a directory listing with count EFIFICNETLY (but I will be caching this anyway), of all the places which are beneath a location.

For example, if I take Europe, then I should see all places which have a parent_id of Europe, and then also the amount of entities below it. Keeping in mind that a place does not get assigned directly to Europe, but might be assigned to a small village in Italy (which is a child of Europe).

You know that it is a child of Europe either because:

  • the lft value of the small village in Italy is between the lft and rgt value of the location
  • Or because the ancestry maps to the place.

For example, Europe would have an ancestry path of /1 and an ID of 5. (The 1 would signify the “World”). And then the small village in Italty would have /1/5/234/28924/124128

where 1 = World 5 = Europe 234 = Italy 28924 = Bergamo etc etc…

Anyway, this is how I have structured the dataset, and I have already been using a mixture of the hierarchical structures in order to make my queries a lot more efficient (for those of you wondering why am I am supporting nested set, adjacency and enumerated.. it’s because I get the best of all structures this way).

This is an example of what I am trying to do.
Example

I am flexible and can change how I manage locations if neccessary. However, this is also a multi tenant application, so I would like to try and avoid saving counts against the geo_places if it can be avoided.

So simply put:
Pick a location… then show all locations which have points of interest assigned either to that location, or a child of that location.

Any recommendations?

  • 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. Editorial Team
    Editorial Team
    2026-05-23T22:55:03+00:00Added an answer on May 23, 2026 at 10:55 pm

    This is one solution:

    select p.woeid, p.name, e.id, e.woeid, e.lft, count(e.lft) from
    geo_places as p
     join  entities as e on e.lft >= p.lft and e.lft < p.rgt
    where p.parent_woeid = 1
    group by p.woeid
    

    You would subtitute 1 for the place that you want to find the descendant of.

    Tested with 100k entities in entities and 8million rows in geo_places.
    Index on lft and rgt and woeid.

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

Sidebar

Related Questions

I am in the phase of learning Zend Framework for PHP development, I have
I have vast programming knowledge; C++/C#/ActionScript/ASM/PHP..... so learning the language of SilverLight itself isn't
I started web development some time ago, but have invested essentially all my time
I have been a long-term .NET developer, but dabble in Java and PHP development
I heard that C# is a rapid application development (RAD) language. Even after reading
If Delphi is the primary language for my development, what is the ideal complement
.NET Framework: 2.0 Preferred Language: C# I am new to TDD (Test Driven Development).
I am planning to participate in development of a code written in C language
Hi I'm looking into iPhone development, and Objective-C is not be my preferred language.
I am very interested in mobile application development. But which language or framework is

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.