What is a Projection?
Asked Answered
N

5

53

What is a Projection, in terms of database theory and NHibernate when using SetProjection()?

Neomineomycin answered 11/8, 2010 at 17:26 Comment(1)
possible duplicate of What is a Projection in NHibernate?Surbase
H
53

Projection is one of the basic operations of Relational Algebra. It takes a relation and a (possibly empty) list of attributes of that relation as input. It outputs a relation containing only the specified list of attributes with duplicate tuples removed. In other words the output must also be a relation.

Example, if the relation R{A,B}, contains three tuples {1,10},{2,10},{3,20} then the projection of R over the attribute list {B} would contain 2 tuples: {10},{20}.

In short, projection is more or less equivalent to SELECT DISTINCT in SQL (excluding cases with nulls and duplicate columns).

Hyksos answered 11/8, 2010 at 19:48 Comment(0)
O
35

Very simply, it's a function which takes an input (e.g. a database row) and produces an output (e.g. one of the columns from the row, or perhaps some calculation based on multiple columns).

Overtire answered 11/8, 2010 at 17:28 Comment(4)
In Hibernate, where does the function that produces the output (e.g. the column) get executed? Does it happen on the SQL database server or does it happen on the application/hibernate server after the full row results are returned? Thanks.Vmail
@KyleM: It's too long since I've used NHibernate to say for sure, but I'd expect it to be executed as part of the SQL.Overtire
Thanks.. that's what I think as well. I just remembered another way to check (hibernate query logging, which we usually don't use..), so I'll check and report back.Vmail
@KyleM: The count projection definitely happens in the SQL, if you look at the query that is issued, it is select count(columnName)Foxhole
H
22

Projection means subset of columns in a query.

select x, y, z from YourTable 

x, y, z is the projection here.

Halley answered 13/2, 2015 at 13:19 Comment(1)
Doesn't it mean "subset of columns" rather than "number of columns"?Malisamalison
O
2

In terms of hibernate, it's like specifying what columns to select. As opposed to letting the mappings determine what columns are fetched. This means you can specify sql functions, subqueries, a single column, or maybe all of the above via a ProjectionList. For example, if you wanted to count the rows in a table SetProjection(Projections.RowCount()).

Overtop answered 11/8, 2010 at 19:59 Comment(0)
S
2

If you are familiar with SQL or database tables: Projection refers to the number of fields/columns/attributes to return. Selection deals with number of rows/records to return. There are good video explanations here and here

Shikoku answered 4/7, 2015 at 19:35 Comment(1)
While these links may answer the question, it is better to include the essential parts of the answer here and provide the links for reference. Link-only answers can become invalid if the linked page changes.Oneself

© 2022 - 2024 — McMap. All rights reserved.