DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. NuGet Perf, Part III–Displaying the Packages page

NuGet Perf, Part III–Displaying the Packages page

Oren Eini user avatar by
Oren Eini
·
Sep. 03, 12 · Interview
Like (0)
Save
Tweet
Share
2.69K Views

Join the DZone community and get the full member experience.

Join For Free

the first thing that we will do with ravendb and the nuget data is to issue the same logical query as the one used to populate the packages page. as a reminder, here is how it looks:

select        top (30) 
          -- ton of fields removed for brevity
from        (

            select        filtered.id
                    ,    filtered.packageregistrationkey
                    ,    filtered.version
                    ,    filtered.downloadcount
                    ,    row_number() over (order by filtered.downloadcount desc, filtered.id asc) as [row_number]
            from        (
                        select        packageregistrations.id
                                ,    packages.packageregistrationkey
                                ,    packages.version
                                ,    packageregistrations.downloadcount
                        from        packages
                        inner join    packageregistrations on packageregistrations.[key] = packages.packageregistrationkey
                        where        packages.isprerelease <> cast(1 as bit)
                        ) filtered
            ) paged
inner join    packageregistrations on packageregistrations.[key] = paged.packageregistrationkey
inner join    packages on packages.packageregistrationkey = paged.packageregistrationkey and packages.version = paged.version
where        paged.[row_number] > 30
order by    packageregistrations.downloadcount desc
        ,    paged.id

despite the apparent complexity ,this is a really trivial query. what is does is say:

  • give me the first 30 – 60 rows
  • where isprerelease is false
  • order by the download count and then the id

with linq, the client side query looks something like this:

var results = session.query<package>()
                         .where(x=>x.isprerelease == false)
                         .orderby(x=>x.downloadcount).thenby(x=>x.id)
                         .skip(30)
                         .take(30)
                         .tolist();

now, i assume that this is what the nuget code is also doing, it is just that the relational database has made it so they have to go to the data in a really convoluted way.

with ravendb, to match the same query, i could just issue the following query, but there are subtle differences between how the query works in sql and how it works in ravendb. in particular, the data that we have in ravendb is the output of this query, but it isn’t the raw output. for example, we don’t have the id column available, which is used for sorting. now, i think that the logic is meaning to say, “sort by download count descending and then by age ascending”. so old and popular packages are more visible than new and fresh packages.

in order to match the same behavior (and because we will need it to the next post) we will define the following index in ravendb:

image

and querying it:

image

the really nice thing about this?

image

this is the url for this search:

/indexes/packages/listing?query=isprerelease:false&start=0&pagesize=128&aggregation=none&sort=-downloadcount&sort=created

this is something that ravendb can do in its sleep, because it is a very cheap operation. consider the query plan that would for the sql query above. you have to join 5 times just to get to the data that you want, paging is a real mess, and the database actually have to work a lot to answer this fiddling little query.

just to give you some idea here. we are talking about something that conceptually should be the same as:

select top 30 skip 30 * from data where isprerelease = 0

but it get really complex really fast with the joins and the tables and all the rest.

in comparison, in ravendb, we actually do have just a property match to do. because we keep the entire object graph in a single location, we can do very efficient searches on it.

in the next post, i’ll discuss the actual way i modeled the data, and then we get to do exciting searches smile .

Relational database Database NuGet

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Explainer: Building High Performing Data Product Platform
  • The 12 Biggest Android App Development Trends in 2023
  • How to Secure Your CI/CD Pipeline
  • Cloud Native London Meetup: 3 Pitfalls Everyone Should Avoid With Cloud Data

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: