Обсуждение: New Window Function: ROW_NUMBER_DESC() OVER() ?

Поиск
Список
Период
Сортировка

New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
Hi developers,

I was working on loans and bank financing, specifically focusing on Amortization Systems. I had the need to reverse the counter for the total number of installments or for a specific set of installments. This "reversal" is essentially a reverse "row_number" function. I realized that it is to "hard work" to write PL/foo functions for this or even to implement it in just SQL using little code.

To streamline the daily process, I conducted a laboratory (prototype, test) using the PostgreSQL 14.3 version doing a small customization. I implemented the window function "row_number_desc," as detailed below.

I would like to assess the feasibility of incorporating this into a future version of Postgres, given its significant utility and practicality in handling bank contract installments in many fields of Finacial Math, because to do use "row_number_desc() over()" is most easy that write a PL/foo or a big lenght SQL string that to do the "descendent case".

What is your opinion regarding this suggestion?
Is it possible to make this a 'feature patch' candidate to PostgreSQL 17?

SUMMARY (IMPLEMENTATION and RESULT):
-------------------------------------------------------------------------------------
/home/postgresql-14.3-custom/src/backend/utils/adt/windowfuncs.c

/*
 * row_number_desc
 * Performs the inverse of row_number function, is a descendent result.
 */
Datum
window_row_number_desc(PG_FUNCTION_ARGS)
{
        WindowObject winobj = PG_WINDOW_OBJECT();
     int64           totalrows = WinGetPartitionRowCount(winobj);
         int64           curpos = WinGetCurrentPosition(winobj);
            
        WinSetMarkPosition(winobj, curpos);
        PG_RETURN_INT64(totalrows - curpos);
}
-------------------------------------------------------------------------------------
/home/postgresql-14.3-custom/src/include/catalog/pg_proc.dat

{ oid => '13882', descr => 'row number descendent within partition',
  proname => 'row_number_desc', prokind => 'w', proisstrict => 'f',
  prorettype => 'int8', proargtypes => '', prosrc => 'window_row_number_desc' },

Note: In this step, I know that I'll need to use an unused OID returned by the 'src/include/catalog/unused_oids' script.
-------------------------------------------------------------------------------------
/home/postgresql-14.3-custom/src/backend/catalog/postgres.bki
insert ( 13882 row_number_desc 11 10 12 1 0 0 0 w f f f f i s 0 0 20 '' _null_ _null_ _null_ _null_ _null_ window_row_number_desc _null_ _null_ _null_ _null_ )

Note: In this step, I know that I'll need to use an unused OID returned by the 'src/include/catalog/unused_oids' script.
-------------------------------------------------------------------------------------
perl -I /home/postgresql-14.3-custom/src/backend/catalog Gen_fmgrtab.pl --include-path / /home/postgresql-14.3-custom/src/include/catalog/pg_proc.dat --output /home

Applying the "row_number() over() DESC" function (basic example):


Tks,
Maiquel Orestes Grassi.
Вложения

Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
"David G. Johnston"
Дата:
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.br> wrote:
Hi developers,

I was working on loans and bank financing, specifically focusing on Amortization Systems. I had the need to reverse the counter for the total number of installments or for a specific set of installments. This "reversal" is essentially a reverse "row_number" function. I realized that it is to "hard work" to write PL/foo functions for this or even to implement it in just SQL using little code.

I think “row_number() over (order by … desc)”  is a sufficient way to get this behavior and this isn’t something useful enough to warrant being the first ordering-specific function in the system.

David J.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
Hello David, how are you?

Firstly, I apologize if I wasn't clear in what I intended to propose. I used a very specific example here, and it wasn't very clear what I really wanted to bring up for discussion.

I understand that it's possible to order the "returned dataset" using "order by ... desc." However, I would like someone to help me think about the following scenario:

Imagine I have a dataset that is returned to my front-end, and I want to reverse enumerate them (exactly the concept of Math enumerating integers). The row_number does the ascending enumeration, but I need the descending enumeration. I don't have a base column to use for "order by," and I also can't use CTID column.

Furthermore, imagine that I have a list of hashes, and I would use "order by" on this column or another column to do the reverse enumeration. This wouldn't work because I wouldn't have the correct reverse enumeration, meaning the reversal of the data would not be original.

It's not about reverse ordering; it's about reverse enumeration.

I apologize again for not being clear in the first interaction.

How can I do this without using my reversed enumeration "row_number desc" function?

Regards,
Maiquel O. Grassi.

De: David G. Johnston <david.g.johnston@gmail.com>
Enviado: terça-feira, 16 de janeiro de 2024 11:30
Para: Maiquel Grassi <grassi@hotmail.com.br>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Assunto: Re: New Window Function: ROW_NUMBER_DESC() OVER() ?
 
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.br> wrote:
Hi developers,

I was working on loans and bank financing, specifically focusing on Amortization Systems. I had the need to reverse the counter for the total number of installments or for a specific set of installments. This "reversal" is essentially a reverse "row_number" function. I realized that it is to "hard work" to write PL/foo functions for this or even to implement it in just SQL using little code.

I think “row_number() over (order by … desc)”  is a sufficient way to get this behavior and this isn’t something useful enough to warrant being the first ordering-specific function in the system.

David J.

Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
"David G. Johnston"
Дата:
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.br> wrote:
Hello David, how are you?

Firstly, I apologize if I wasn't clear in what I intended to propose. I used a very specific example here, and it wasn't very clear what I really wanted to bring up for discussion.

I understand that it's possible to order the "returned dataset" using "order by ... desc."


It is, but it is also possible to order a window frame/partition by specifying order by in the over clause.  Which is what I showed, and what you should try to use.  That orders the enumeration, you can still order, or not, the output dataset.

 
I don't have a base column to use for "order by," and I also can't use CTID column.

Then you really don’t have an ordering in the data itself.  This is unusual and not really worth adding a new function to deal with.
 

How can I do this without using my reversed enumeration "row_number desc" function?

Count() over() - row_number() over()

 Please don’t top-post replies, in-line and trim like I’m doing.

David J.

P.s. if you really don’t care about logical order you probably should just let your front-end deal with it.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
Hi,

Count() over() - row_number() over()
  
   But if my dataset is significantly large? Wouldn't calling two window functions instead of one be much slower?
   Is count() over() - row_number() over() faster than row_number_desc() over()?

Maiquel.

New Window Function: ROW_NUMBER_DESC() OVER() ?

От
"David G. Johnston"
Дата:
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.br> wrote:
Hi,

Count() over() - row_number() over()
  
   But if my dataset is significantly large? Wouldn't calling two window functions instead of one be much slower?
   Is count() over() - row_number() over() faster than row_number_desc() over()?


I doubt it is materially different, you need that count regardless so the effort is expended no matter if you put it in an SQL expression or build it into the window function.  But as you are the one arguing for the new feature demonstrating that the status quo is deficient is your job.

David J.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
I doubt it is materially different, you need that count regardless so the effort is expended no matter if you put it in an SQL expression or build it into the window function.  But as you are the one arguing for the new feature demonstrating that the status quo is deficient is your job.

---//---

Ok, I'll run the tests to validate these performances and draw some conclusions.

However, initially, I have one more obstacle in your feedback. If I use count(*) over() - row_number() over(), it gives me an offset of one unit. To resolve this, I need to add 1. This way, simulating a reverse row_number() becomes even more laborious.

SELECT
      row_number() over()
      , row_number_desc() over()
      , count(*) over() - row_number() over() as FROM pg_catalog.pg_database;
 row_number | row_number_desc | count_minus_row_number
------------+-----------------+------------------------
          1 |               3 |                      2
          2 |               2 |                      1
          3 |               1 |                      0
(3 rows)

postgres=# SELECT row_number() over(), row_number_desc() over(), count(*) over() - row_number() over() as count_minus_row_number, count(*) over() - row_number() over() + 1 AS count_minus_row_number_plus_one FROM pg_catalog.pg_database;
 row_number | row_number_desc | count_minus_row_number | count_minus_row_number_plus_one
------------+-----------------+------------------------+---------------------------------
          1 |               3 |                      2 |                               3
          2 |               2 |                      1 |                               2
          3 |               1 |                      0 |                               1
(3 rows)

Tks,
Maiquel.

Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Michał Kłeczek
Дата:


On 16 Jan 2024, at 16:51, Maiquel Grassi <grassi@hotmail.com.br> wrote:


Imagine I have a dataset that is returned to my front-end, and I want to reverse enumerate them (exactly the concept of Math enumerating integers). The row_number does the ascending enumeration, but I need the descending enumeration.

You can do:

-(ROW_NUMBER() OVER ()) AS descending

(note “-“ in front)

I don't have a base column to use for "order by,"

I think that’s the main issue: what (semantically) does row_number() mean in that case? You could equally well generate random numbers?


— 
Michal

New Window Function: ROW_NUMBER_DESC() OVER() ?

От
"David G. Johnston"
Дата:
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.br> wrote:

However, initially, I have one more obstacle in your feedback. If I use count(*) over() - row_number() over(), it gives me an offset of one unit. To resolve this, I need to add 1. 

This way, simulating a reverse row_number() becomes even more laborious.

I don’t really understand why you think this reverse inserted counting is even a good idea so I don’t really care how laborious it is to implement with existing off-the-shelf tools.  A window function named “descending” is non-standard and seemingly non-sensical and should not be added.  You can specify order by in the over clause and that is what you should be doing.  Mortgage payments are usually monthly, so order by date.

David J.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
You can do:

-(ROW_NUMBER() OVER ()) AS descending

(note “-“ in front)

I don't have a base column to use for "order by,"

I think that’s the main issue: what (semantically) does row_number() mean in that case? You could equally well generate random numbers?

--//--

What I want to do is inverse the enumeration using a simple solution. I want to look at the enumeration of the dataset list from bottom to top, not from top to bottom. I don't want to reverse the sign of the integers. The generated integers in output remain positive.The returned dataset can be from any query. What I need is exactly the opposite of row_number().


count(*) over() - row_number() + 1 works.

But I think for a large volume of data, its performance will be inferior to the suggested row_number_desc() over(). I may be very wrong, so I will test it.

Maiquel.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
However, initially, I have one more obstacle in your feedback. If I use count(*) over() - row_number() over(), it gives me an offset of one unit. To resolve this, I need to add 1. 

This way, simulating a reverse row_number() becomes even more laborious.

I don’t really understand why you think this reverse inserted counting is even a good idea so I don’t really care how laborious it is to implement with existing off-the-shelf tools.  A window function named “descending” is non-standard and seemingly non-sensical and should not be added.  You can specify order by in the over clause and that is what you should be doing.  Mortgage payments are usually monthly, so order by date.

David J.

--//--

We are just raising hypotheses and discussing healthy possibilities here. This is a suggestion for knowledge and community growth. Note that this is not about a new "feature patch." I am asking for the community's opinion in general. Your responses are largely appearing aggressive and depreciative. Kindly request you to be more welcoming in your answers and not oppressive. This way, the community progresses more rapidly.

Maiquel.

New Window Function: ROW_NUMBER_DESC() OVER() ?

От
"David G. Johnston"
Дата:
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.br> wrote:
However, initially, I have one more obstacle in your feedback. If I use count(*) over() - row_number() over(), it gives me an offset of one unit. To resolve this, I need to add 1. 

This way, simulating a reverse row_number() becomes even more laborious.

I don’t really understand why you think this reverse inserted counting is even a good idea so I don’t really care how laborious it is to implement with existing off-the-shelf tools.  A window function named “descending” is non-standard and seemingly non-sensical and should not be added.  You can specify order by in the over clause and that is what you should be doing.  Mortgage payments are usually monthly, so order by date.

David J.

--//--

We are just raising hypotheses and discussing healthy possibilities here. This is a suggestion for knowledge and community growth. Note that this is not about a new "feature patch.


That is not how your initial post here came across.  It seemed quite concrete in goal and use case motivating that goal.


I am asking for the community's opinion in general. Your responses are largely appearing aggressive and depreciative. Kindly request you to be more welcoming in your answers and not oppressive. This way, the community progresses more rapidly..


The people in this community are quite capable and willing to write a contrary opinion to mine.  Not sure how to make “this new proposed function shouldn’t be added to core”, and trying to explain why not, non-oppressive.  I can add “thank you for taking the time to try and improve PostgreSQL” in front to soften the blow of rejection but I tend to just get to the point.

David J.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
The people in this community are quite capable and willing to write a contrary opinion to mine.  Not sure how to make “this new proposed function shouldn’t be added to core”, and trying to explain why not, non-oppressive.  I can add “thank you for taking the time to try and improve PostgreSQL” in front to soften the blow of rejection but I tend to just get to the point.

David J.

----//----

Thank you for your opinion. We built together one more insight on PostgreSQL for the community.

Best regards,
Maiquel O.

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
But as you are the one arguing for the new feature demonstrating that the status quo is deficient is your job.

--//--

I performed these three tests(take a look below) quite simple but functional, so that we can get an idea of the performance. Apparently, we have a higher cost in using "count(*) - row_number() + 1" than in using "row_number_desc() over()".

Perhaps, if we think in terms of SQL standards, my suggested name may not have been the best. The name could be anything else. I don't have another suggestion. Does anyone have a better one? I leave it open for others to also reflect.



postgres=# select * into public.foo_1 from generate_series(1,1000000);
SELECT 1000000
postgres=# explain analyze select count(*) over() - row_number() over() + 1 from public.foo_1;
                                                      QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
 WindowAgg  (cost=0.00..38276.25 rows=1128375 width=8) (actual time=244.878..475.595 rows=1000000 loops=1)
   ->  Seq Scan on foo_1  (cost=0.00..15708.75 rows=1128375 width=0) (actual time=0.033..91.486 rows=1000000 loops=1)
 Planning Time: 0.073 ms
 Execution Time: 505.375 ms
(4 rows)

postgres=# explain analyze select row_number_desc() over() from public.foo_1;
                                                      QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
 WindowAgg  (cost=0.00..26925.00 rows=1000000 width=8) (actual time=141.107..427.100 rows=1000000 loops=1)
   ->  Seq Scan on foo_1  (cost=0.00..14425.00 rows=1000000 width=0) (actual time=0.031..61.651 rows=1000000 loops=1)
 Planning Time: 0.051 ms
 Execution Time: 466.535 ms
(4 rows)



postgres=# select * into public.foo_2 from generate_series(1,10000000);
SELECT 10000000
postgres=# explain analyze select count(*) over() - row_number() over() + 1 from public.foo_2;
                                                       QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
 WindowAgg  (cost=0.00..344247.31 rows=9999977 width=8) (actual time=2621.014..5145.325 rows=10000000 loops=1)
   ->  Seq Scan on foo_2  (cost=0.00..144247.77 rows=9999977 width=0) (actual time=0.031..821.533 rows=10000000 loops=1)
 Planning Time: 0.085 ms
 Execution Time: 5473.422 ms
(4 rows)

postgres=# explain analyze select row_number_desc() over() from public.foo_2;
                                                       QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
 WindowAgg  (cost=0.00..269247.48 rows=9999977 width=8) (actual time=1941.915..4527.896 rows=10000000 loops=1)
   ->  Seq Scan on foo_2  (cost=0.00..144247.77 rows=9999977 width=0) (actual time=0.029..876.802 rows=10000000 loops=1)
 Planning Time: 0.030 ms
 Execution Time: 4871.278 ms
(4 rows)




postgres=# select * into public.foo_3 from generate_series(1,100000000);
SELECT 100000000
postgres=# explain analyze select count(*) over() - row_number() over() + 1 from public.foo_3;
                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 WindowAgg  (cost=0.00..3827434.70 rows=112831890 width=8) (actual time=56823.080..84295.660 rows=100000000 loops=1)
   ->  Seq Scan on foo_3  (cost=0.00..1570796.90 rows=112831890 width=0) (actual time=1.010..37735.121 rows=100000000 loops=1)
 Planning Time: 1.018 ms
 Execution Time: 87677.572 ms
(4 rows)

postgres=# explain analyze select row_number_desc() over() from public.foo_3;
                                                           QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
 WindowAgg  (cost=0.00..2981195.53 rows=112831890 width=8) (actual time=29523.037..55517.349 rows=100000000 loops=1)
   ->  Seq Scan on foo_3  (cost=0.00..1570796.90 rows=112831890 width=0) (actual time=12.638..19050.614 rows=100000000 loops=1)
 Planning Time: 55.653 ms
 Execution Time: 59001.423 ms
(4 rows)



Regards,
Maiquel.

Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
David Rowley
Дата:
On Wed, 17 Jan 2024 at 08:51, Michał Kłeczek <michal@kleczek.org> wrote:
> I think that’s the main issue: what (semantically) does row_number() mean in that case? You could equally well
generaterandom numbers? 

Well, not quite random as at least row_number() would ensure the
number is unique in the result set. The point I think you're trying to
make is very valid though.

To reinforce that point, here's an example how undefined the behaviour
that Maique is relying on:

create table t (a int primary key);
insert into t values(3),(2),(4),(1),(5);

select a,row_number() over() from t; -- Seq Scan
 a | row_number
---+------------
 3 |          1
 2 |          2
 4 |          3
 1 |          4
 5 |          5

set enable_seqscan=0;
set enable_bitmapscan=0;

select a,row_number() over() from t; -- Index Scan
 a | row_number
---+------------
 1 |          1
 2 |          2
 3 |          3
 4 |          4
 5 |          5

i.e the row numbers are just assigned in whichever order they're given
to the WindowAgg node.

Maique,

As far as I see your proposal, you want to allow something that is
undefined to be reversed.  I don't think this is a good idea at all.
As mentioned by others, you should have ORDER BY clauses and just add
a DESC.

If you were looking for something to optimize in this rough area, then
perhaps adding some kind of "Backward WindowAgg" node (by overloading
the existing node) to allow queries such as the following to be
executed without an additional sort.

SELECT a,row_number() over (order by a desc) from t order by a;

The planner complexity is likely fairly easy to implement that. I
don't think we'd need to generate any additional Paths. We could
invent some pathkeys_contained_in_reverse() function and switch on the
Backward flag if it is.

The complexity would be in nodeWindowAgg.c... perhaps too much
complexity for it to be worthwhile and not add additional overhead to
the non-backward case.

Or, it might be easier to invent "Backward Materialize" instead and
just have the planner use on of those instead of the final sort.

David



RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
As far as I see your proposal, you want to allow something that is
undefined to be reversed.  I don't think this is a good idea at all.
As mentioned by others, you should have ORDER BY clauses and just add
a DESC.

If you were looking for something to optimize in this rough area, then
perhaps adding some kind of "Backward WindowAgg" node (by overloading
the existing node) to allow queries such as the following to be
executed without an additional sort.

SELECT a,row_number() over (order by a desc) from t order by a;

The planner complexity is likely fairly easy to implement that. I
don't think we'd need to generate any additional Paths. We could
invent some pathkeys_contained_in_reverse() function and switch on the
Backward flag if it is.

The complexity would be in nodeWindowAgg.c... perhaps too much
complexity for it to be worthwhile and not add additional overhead to
the non-backward case.

Or, it might be easier to invent "Backward Materialize" instead and
just have the planner use on of those instead of the final sort.

David

RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:
As far as I see your proposal, you want to allow something that is
undefined to be reversed.  I don't think this is a good idea at all.
As mentioned by others, you should have ORDER BY clauses and just add
a DESC.

  • Okay, now I'm convinced of that.

If you were looking for something to optimize in this rough area, then
perhaps adding some kind of "Backward WindowAgg" node (by overloading
the existing node) to allow queries such as the following to be
executed without an additional sort.

SELECT a,row_number() over (order by a desc) from t order by a;

  • David, considering this optimization, allowing for that, do you believe it is plausible to try advancing towards a possible Proof of Concept (PoC) implementation?

Maiquel.

Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
David Rowley
Дата:
On Wed, 17 Jan 2024 at 15:28, Maiquel Grassi <grassi@hotmail.com.br> wrote:
> On Wed, 17 Jan 2024 at 14:36, David Rowley <dgrowleyml@gmail.com> wrote:
> > If you were looking for something to optimize in this rough area, then
> > perhaps adding some kind of "Backward WindowAgg" node (by overloading
> > the existing node) to allow queries such as the following to be
> > executed without an additional sort.
> >
> > SELECT a,row_number() over (order by a desc) from t order by a;
>
> David, considering this optimization, allowing for that, do you believe it is plausible to try advancing towards a
possibleProof of Concept (PoC) implementation?
 

I think the largest factor which would influence the success of that
would be how much more complex nodeWindowAgg.c would become.

There's a couple of good ways to ensure such a patch fails:

1. Copy and paste all the code out of nodeWindowAgg.c and create
nodeWindowAggBackward.c and leave a huge maintenance burden. (don't do
this)
2. Make nodeWindowAgg.c much more complex and slower by adding dozens
of conditions to check if we're in backward mode.

I've not taken the time to study nodeWindowAgg.c to know how much more
complex supporting reading the tuples backwards would make it.
Certainly the use of tuplestore_trim() would have to change and
obviously way we read stored tuples back would need to be adjusted. It
might just add much more complexity than it would be worth.  Part of
the work would be finding this out.

If making the changes to nodeWindowAgg.c is too complex, then
adjusting nodeMaterial.c would at least put us in a better position
than having to sort twice.  You'd have to add a bool isbackward flag
to MaterialPath and then likely add a ScanDirection normal_dir to
MaterialState then set "dir" in ExecMaterial() using
ScanDirectionCombine of the two scan directions.   At least some of
what's there would work as a result of that, but likely a few other
things in ExecMaterial() would need to be rejiggered.  explain.c would
need to show "Backward Material", etc.

Both cases you'd need to modify planner.c's create_one_window_path()
and invent a function such as pathkeys_count_contained_in_backward()
or at least pathkeys_contained_in_backward() to detect when you need
to use the backward node type.

I'd go looking at nodeWindowAgg.c first, if you're interested.

David



Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Tom Lane
Дата:
David Rowley <dgrowleyml@gmail.com> writes:
> On Wed, 17 Jan 2024 at 15:28, Maiquel Grassi <grassi@hotmail.com.br> wrote:
>> On Wed, 17 Jan 2024 at 14:36, David Rowley <dgrowleyml@gmail.com> wrote:
>>> If you were looking for something to optimize in this rough area, then
>>> perhaps adding some kind of "Backward WindowAgg" node (by overloading
>>> the existing node) to allow queries such as the following to be
>>> executed without an additional sort.
>>>
>>> SELECT a,row_number() over (order by a desc) from t order by a;

>> David, considering this optimization, allowing for that, do you believe it is plausible to try advancing towards a
possibleProof of Concept (PoC) implementation? 

> I think the largest factor which would influence the success of that
> would be how much more complex nodeWindowAgg.c would become.

Even if a workable patch for that is presented, should we accept it?
I'm having a hard time believing that this requirement is common
enough to justify more than a microscopic addition of complexity.
This whole area is devilishly complicated already, and I can think of
a bunch of improvements that I'd rate as more worthy of developer
effort than this.

            regards, tom lane



RE: New Window Function: ROW_NUMBER_DESC() OVER() ?

От
Maiquel Grassi
Дата:

Even if a workable patch for that is presented, should we accept it?
I'm having a hard time believing that this requirement is common
enough to justify more than a microscopic addition of complexity.
This whole area is devilishly complicated already, and I can think of
a bunch of improvements that I'd rate as more worthy of developer
effort than this.

--//--

Thanks for the advice. I understand that an improvement you consider microscopic may not be worth spending time trying to implement it (considering you are already warning that a good patch might not be accepted). But since you mentioned that you can think of several possible improvements, more worthy of time investment, could you share at least one of them with us that you consider a candidate for an effort?


Regards,
Maiquel.